fix(router): validate context_window_fallbacks at init

This commit is contained in:
soroush5 2026-09-04 01:42:06 +03:30
parent 4b1e24eae9
commit fca903b416
2 changed files with 9 additions and 0 deletions

View file

@ -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)

View file

@ -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"])