diff --git a/litellm/proxy/proxy_cli.py b/litellm/proxy/proxy_cli.py index 01a3da08998..641bddc1d93 100644 --- a/litellm/proxy/proxy_cli.py +++ b/litellm/proxy/proxy_cli.py @@ -1174,6 +1174,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 e25e6a59884..6c545e8b3ed 100644 --- a/tests/test_litellm/proxy/test_proxy_cli.py +++ b/tests/test_litellm/proxy/test_proxy_cli.py @@ -2863,3 +2863,31 @@ class TestLibpqSslParamTranslation: assert query["sslmode"] == ["require"] assert query["sslcert"] == ["/certs/rds-bundle.pem"] assert query["sslaccept"] == ["strict"] + + +@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))