From 430d931ff841fb39356d68c658095fa0cbf473c1 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Thu, 1 Oct 2026 17:31:16 -0700 Subject: [PATCH] refactor(router): read a deployment's declared prefill support without an empty except --- .../continuation_prefill_check.py | 19 ++++++++++++------- .../test_continuation_prefill_check.py | 2 ++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/litellm/router_utils/pre_call_checks/continuation_prefill_check.py b/litellm/router_utils/pre_call_checks/continuation_prefill_check.py index 0d6d462d417..2bde8ca920d 100644 --- a/litellm/router_utils/pre_call_checks/continuation_prefill_check.py +++ b/litellm/router_utils/pre_call_checks/continuation_prefill_check.py @@ -24,18 +24,23 @@ MID_STREAM_CONTINUATION_MARKER: Final = _ContinuationMarker() _STR_KEYED_DICT_ADAPTER: Final = TypeAdapter(dict[str, object]) +def _declared_prefill_support(deployment_map: Mapping[str, object]) -> bool | None: + try: + model_info: Final = _STR_KEYED_DICT_ADAPTER.validate_python(deployment_map.get("model_info")) + except ValidationError: + return None + declared: Final = model_info.get("supports_assistant_prefill") + return declared if isinstance(declared, bool) else None + + def _deployment_supports_prefill(deployment: object) -> bool: try: deployment_map: Final = _STR_KEYED_DICT_ADAPTER.validate_python(deployment) except ValidationError: return False - try: - model_info: Final = _STR_KEYED_DICT_ADAPTER.validate_python(deployment_map.get("model_info")) - declared: Final = model_info.get("supports_assistant_prefill") - if isinstance(declared, bool): - return declared - except ValidationError: - pass + declared: Final = _declared_prefill_support(deployment_map) + if declared is not None: + return declared try: litellm_params: Final = _STR_KEYED_DICT_ADAPTER.validate_python(deployment_map.get("litellm_params")) except ValidationError: diff --git a/tests/unit/router_utils/pre_call_checks/test_continuation_prefill_check.py b/tests/unit/router_utils/pre_call_checks/test_continuation_prefill_check.py index bf3ff3c6b4f..4cbe48eda54 100644 --- a/tests/unit/router_utils/pre_call_checks/test_continuation_prefill_check.py +++ b/tests/unit/router_utils/pre_call_checks/test_continuation_prefill_check.py @@ -32,6 +32,8 @@ def _deployment(model: str, dep_id: str) -> dict: def test_deployment_supports_prefill_reads_capability(): assert _deployment_supports_prefill(_deployment(PREFILL_MODEL, "a")) is True assert _deployment_supports_prefill(_deployment(NON_PREFILL_MODEL, "b")) is False + assert _deployment_supports_prefill({"litellm_params": {"model": PREFILL_MODEL}}) is True + assert _deployment_supports_prefill({"litellm_params": {"model": PREFILL_MODEL}, "model_info": "bogus"}) is True def test_deployment_model_info_override_wins_over_cost_map():