From c575ac781304c95c3c35477a7e1ca0ce52fa856e Mon Sep 17 00:00:00 2001 From: Ryan Crabbe Date: Tue, 17 Feb 2026 12:31:02 -0800 Subject: [PATCH] fix: restore args = locals() at original position to avoid leaking extra vars Reverts the deferred locals() change. The deferred call at line 1286/1291 captured ~50 extra local variables and caused a TypeError on the batch_completion_models path (deployments passed as both explicit kwarg and in **locals()). Restores args = locals() at its original position before kwargs unpacking. Keeps the LlmProvidersSet and minimal {"messages": messages} changes which are safe. --- litellm/main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/litellm/main.py b/litellm/main.py index 316e5a811fd..cb736bbe7e8 100644 --- a/litellm/main.py +++ b/litellm/main.py @@ -1104,6 +1104,7 @@ def completion( # type: ignore # noqa: PLR0915 # validate optional params stop = validate_openai_optional_params(stop=stop) + args = locals() ######### unpacking kwargs ##################### skip_mcp_handler = kwargs.pop("_skip_mcp_handler", False) if not skip_mcp_handler and tools: @@ -1283,12 +1284,12 @@ def completion( # type: ignore # noqa: PLR0915 logging: LiteLLMLoggingObj = cast(LiteLLMLoggingObj, litellm_logging_obj) fallbacks = fallbacks or litellm.model_fallbacks if fallbacks is not None: - return completion_with_fallbacks(**locals()) + return completion_with_fallbacks(**args) if model_list is not None: deployments = [ m["litellm_params"] for m in model_list if m["model_name"] == model ] - return litellm.batch_completion_models(deployments=deployments, **locals()) + return litellm.batch_completion_models(deployments=deployments, **args) if litellm.model_alias_map and model in litellm.model_alias_map: model = litellm.model_alias_map[ model