From 6882a2e88e702fd8d708a3d18e2f506e68ab6eba Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 17 Sep 2026 18:06:28 +0000 Subject: [PATCH] fix(proxy): satisfy strict lint gates in model routability check Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- litellm/proxy/common_request_processing.py | 3 +-- litellm/proxy/route_llm_request.py | 27 ++++++++++++++-------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/litellm/proxy/common_request_processing.py b/litellm/proxy/common_request_processing.py index 6fd513a88cc..55084835159 100644 --- a/litellm/proxy/common_request_processing.py +++ b/litellm/proxy/common_request_processing.py @@ -16,7 +16,6 @@ from typing import ( Protocol, TypeAlias, TypeVar, - cast, overload, runtime_checkable, ) @@ -2105,7 +2104,7 @@ class ProxyBaseLLMRequestProcessing: if self._tags_before_guardrails is None: self._tags_before_guardrails = frozenset(get_tags_from_request_body(request_body=self.data)) await raise_if_model_not_routable( - data=cast(dict[str, object], self.data), + data=self.data, # pyright: ignore[reportUnknownMemberType, reportUnknownArgumentType] # loosely typed llm_router=llm_router, user_model=user_model, route_type=route_type, diff --git a/litellm/proxy/route_llm_request.py b/litellm/proxy/route_llm_request.py index d827bb7c6b1..68365271864 100644 --- a/litellm/proxy/route_llm_request.py +++ b/litellm/proxy/route_llm_request.py @@ -1,6 +1,6 @@ import asyncio from collections.abc import Mapping -from typing import TYPE_CHECKING, Any, Final, Literal, cast +from typing import TYPE_CHECKING, Any, Final, Literal import httpx from fastapi import HTTPException, status @@ -610,27 +610,36 @@ def _router_can_route( if not isinstance(model, str): return True + return _router_model_group_routable(model=model, llm_router=llm_router, data=data, route_type=route_type) + + +def _router_model_group_routable( + model: str, + llm_router: LitellmRouter, + data: Mapping[str, object], + route_type: str, +) -> bool: team_id: Final = get_team_id_from_data(dict(data)) if team_id is not None and llm_router.map_team_model(model, team_id) is not None: return True - router_model_names: Final = cast(set[str], llm_router.model_names) is_proxy_admin_without_team: Final = team_id is None and _is_proxy_admin_request(dict(data)) if ( - is_proxy_admin_without_team and model not in router_model_names and model in llm_router.team_public_model_names + is_proxy_admin_without_team + and model not in llm_router.model_names # pyright: ignore[reportUnknownMemberType] # bare set + and model in llm_router.team_public_model_names ) or llm_router.is_recognized_model(model): return True - if model in router_model_names: + if model in llm_router.model_names: # pyright: ignore[reportUnknownMemberType] # bare set return False if llm_router.router_general_settings.pass_through_all_models: return True - if ( - llm_router.default_deployment is not None - or len(cast(dict[str, object], llm_router.pattern_router.patterns)) > 0 - ): + if llm_router.default_deployment is not None: return True - if model in cast(list[str], llm_router.deployment_names): + if llm_router.pattern_router.patterns: # pyright: ignore[reportUnknownMemberType] # untyped dict + return True + if model in llm_router.deployment_names: # pyright: ignore[reportUnknownMemberType] # bare list return True if route_type in _MODEL_OPTIONAL_FALLBACK_ROUTE_TYPES or route_type in _VIDEO_FALLBACK_ROUTE_TYPES: return True