diff --git a/litellm/proxy/proxy_cli.py b/litellm/proxy/proxy_cli.py index 23932ba7c8c..baa6b29693c 100644 --- a/litellm/proxy/proxy_cli.py +++ b/litellm/proxy/proxy_cli.py @@ -1151,6 +1151,12 @@ def run_server( general_settings = _config.get("general_settings", {}) if general_settings is None: general_settings = {} + elif not isinstance(general_settings, dict): + raise ValueError( + "`general_settings` in the proxy config must be a mapping " + f"(got {type(general_settings).__name__}). Check the " + "`general_settings:` block in your config file." + ) ### LOAD KEY MANAGEMENT SETTINGS FIRST (needed for custom secret manager) ### key_management_settings: Final = general_settings.get("key_management_settings", None) if key_management_settings is not None: diff --git a/tests/test_litellm/proxy/test_proxy_cli.py b/tests/test_litellm/proxy/test_proxy_cli.py index 3e70dee23b7..1dc7db85d7b 100644 --- a/tests/test_litellm/proxy/test_proxy_cli.py +++ b/tests/test_litellm/proxy/test_proxy_cli.py @@ -2622,3 +2622,31 @@ class TestTokenAuthCliFlags: assert result.exit_code == 0, f"exit_code={result.exit_code}, output={result.output}" assert "ENTRA_TOKEN" not in (database_url or "") assert toggle is None + + +@pytest.mark.xdist_group("proxy_cli") +class TestGeneralSettingsShape: + """`general_settings` is read straight from user YAML. A non-mapping value + (a bare string when the block is malformed, or `null` from an empty block) + used to reach `general_settings.get(...)` and blow up at startup with an + opaque `AttributeError: 'str' object has no attribute 'get'`. Startup must + either tolerate it (None -> {}) or fail with a message pointing at the config. + """ + + def test_null_general_settings_is_tolerated(self, tmp_path): + """An empty `general_settings:` block parses as None and must not crash.""" + config_path = tmp_path / "config.yaml" + config_path.write_text(yaml.dump({"model_list": [], "general_settings": None})) + + captured = _run_server_and_capture_urls(str(config_path)) + assert captured["DATABASE_URL"].startswith("postgresql://t:t@localhost:5432/t") + + def test_string_general_settings_fails_with_actionable_error(self, tmp_path): + """A non-mapping value must fail fast, not as a cryptic AttributeError.""" + config_path = tmp_path / "config.yaml" + config_path.write_text( + yaml.dump({"model_list": [], "general_settings": "database_url"}) + ) + + with pytest.raises(ValueError, match=r"general_settings.*must be a mapping"): + _run_server_and_capture_urls(str(config_path))