From fca903b416d98a8474689f050df2f66da562fa5d Mon Sep 17 00:00:00 2001 From: soroush5 Date: Fri, 4 Sep 2026 01:42:06 +0330 Subject: [PATCH] fix(router): validate context_window_fallbacks at init --- litellm/router.py | 1 + tests/router_unit_tests/test_router_helper_utils.py | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/litellm/router.py b/litellm/router.py index 2b8b342d253..d23f6f1eeb7 100644 --- a/litellm/router.py +++ b/litellm/router.py @@ -951,6 +951,7 @@ class Router: self.fallbacks = [{"*": _fallbacks}] self.context_window_fallbacks = context_window_fallbacks or litellm.context_window_fallbacks + self.validate_fallbacks(fallback_param=self.context_window_fallbacks) _content_policy_fallbacks: Final = content_policy_fallbacks or litellm.content_policy_fallbacks self.validate_fallbacks(fallback_param=_content_policy_fallbacks) diff --git a/tests/router_unit_tests/test_router_helper_utils.py b/tests/router_unit_tests/test_router_helper_utils.py index 7dbac243d55..d5fe3d0253d 100644 --- a/tests/router_unit_tests/test_router_helper_utils.py +++ b/tests/router_unit_tests/test_router_helper_utils.py @@ -2825,3 +2825,11 @@ def test_upsert_deployment_clears_stale_budget_config(monkeypatch): router.upsert_deployment(deployment=unbudgeted) assert budget_limiter._get_budget_config_for_deployment(model_id) is None + + +def test_context_window_fallbacks_validated_at_init(model_list): + """Malformed context_window_fallbacks must fail fast like the sibling params (#39655).""" + import pytest + + with pytest.raises(ValueError, match="not a dictionary"): + Router(model_list=model_list, context_window_fallbacks=["garbage"])