From 4e12bf268abea32e5f236ef25d0063ca3687c3e3 Mon Sep 17 00:00:00 2001 From: Jim Smith Date: Wed, 24 Jun 2026 06:43:23 -0400 Subject: [PATCH] fix: read rerank `instruction` from kwargs to satisfy basedpyright budget The basedpyright delta-vs-base gate flagged one new reportArgumentType: the Router forwards rerank calls via an untyped `**kwargs` unpack (`litellm.arerank(**{**data, **kwargs})`), and declaring `instruction` as a typed named param on the public `rerank`/`arerank` entrypoints made pyright check that key against `str | None`, adding an error at router.py with no real safety gain. Read `instruction` from kwargs in `rerank` instead. It remains fully typed where it matters - threaded as a typed argument through `get_optional_rerank_params` and each provider's `map_cohere_rerank_params` (the original Greptile P2 ask). Whole-repo reportArgumentType is back to the base count (net 0); rerank hosted_vllm + cohere guardrail suites pass; ruff clean. --- litellm/rerank_api/main.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/litellm/rerank_api/main.py b/litellm/rerank_api/main.py index d24d0bcb8be..3ef74d596ad 100644 --- a/litellm/rerank_api/main.py +++ b/litellm/rerank_api/main.py @@ -39,7 +39,6 @@ async def arerank( rank_fields: Optional[List[str]] = None, return_documents: Optional[bool] = None, max_chunks_per_doc: Optional[int] = None, - instruction: Optional[str] = None, **kwargs, ) -> Union[RerankResponse, Coroutine[Any, Any, RerankResponse]]: """ @@ -59,7 +58,6 @@ async def arerank( rank_fields, return_documents, max_chunks_per_doc, - instruction=instruction, **kwargs, ) @@ -100,12 +98,16 @@ def rerank( return_documents: Optional[bool] = True, max_chunks_per_doc: Optional[int] = None, max_tokens_per_doc: Optional[int] = None, - instruction: Optional[str] = None, **kwargs, ) -> Union[RerankResponse, Coroutine[Any, Any, RerankResponse]]: """ Reranks a list of documents based on their relevance to the query """ + # `instruction` is read from kwargs rather than declared as a named param. + # The router forwards rerank calls via an untyped `**kwargs` unpack, and a + # typed named param there would trip the basedpyright budget gate without + # adding real safety; it stays typed downstream via get_optional_rerank_params. + instruction: Optional[str] = kwargs.get("instruction", None) headers: Optional[dict] = kwargs.get("headers") # type: ignore litellm_logging_obj: LiteLLMLoggingObj = kwargs.get("litellm_logging_obj") # type: ignore litellm_call_id: Optional[str] = kwargs.get("litellm_call_id", None)