From 59c8e36added808edc98879f337d5d264f627db9 Mon Sep 17 00:00:00 2001 From: mutnale_sushant Date: Fri, 10 Jul 2026 11:55:41 +0530 Subject: [PATCH] fix(param_utils): resolve type-discipline and basedpyright violations in sanitization utility and registry --- .../custom_logger_registry.py | 2 +- litellm/litellm_core_utils/param_utils.py | 30 +++++++++++-------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/litellm/litellm_core_utils/custom_logger_registry.py b/litellm/litellm_core_utils/custom_logger_registry.py index eb7bbc79971..b970426f21c 100644 --- a/litellm/litellm_core_utils/custom_logger_registry.py +++ b/litellm/litellm_core_utils/custom_logger_registry.py @@ -60,7 +60,7 @@ class CustomLoggerRegistry: Registry mapping the callback class string to the class type. """ - CALLBACK_CLASS_STR_TO_CLASS_TYPE: dict[str, type[object]] = { + CALLBACK_CLASS_STR_TO_CLASS_TYPE: dict[str, type[object]] = { # mutable-ok: global callback registry mapping "lago": LagoLogger, "openmeter": OpenMeterLogger, "braintrust": BraintrustLogger, diff --git a/litellm/litellm_core_utils/param_utils.py b/litellm/litellm_core_utils/param_utils.py index d3eeda00c60..832f885573d 100644 --- a/litellm/litellm_core_utils/param_utils.py +++ b/litellm/litellm_core_utils/param_utils.py @@ -2,18 +2,22 @@ import logging logger = logging.getLogger(__name__) -LITELLM_INTERNAL_PARAM_NAMES = { - "litellm_params", - "proxy_server_request", - "model_info", - "metadata", - "preset_cache_key", - "litellm_metadata", - "acompletion", -} +LITELLM_INTERNAL_PARAM_NAMES = frozenset( + ( + "litellm_params", + "proxy_server_request", + "model_info", + "metadata", + "preset_cache_key", + "litellm_metadata", + "acompletion", + ) +) -def strip_litellm_internal_params(data: dict[str, object]) -> dict[str, object]: +def strip_litellm_internal_params( + data: dict[str, object], # mutable-ok: interface expects mutable dict payload +) -> dict[str, object]: # mutable-ok: returns mutable dict payload """ Remove LiteLLM internal params (e.g. litellm_params, proxy_server_request, _litellm_ prefixed keys) from request data before passing to client libraries (e.g. OpenAI). @@ -25,13 +29,13 @@ def strip_litellm_internal_params(data: dict[str, object]) -> dict[str, object]: try: # Create a shallow copy so we don't modify the input dictionary in-place - cleaned_data: dict[str, object] = {} + cleaned_data: dict[str, object] = {} # mutable-ok: building cleaned payload dict for key, value in data.items(): if key in LITELLM_INTERNAL_PARAM_NAMES or key.startswith("_litellm_"): continue if key == "extra_body" and isinstance(value, dict): - cleaned_extra_body: dict[str, object] = {} - extra_body_dict: dict[object, object] = value # pyright: ignore[reportUnknownVariableType] # cast from dynamic dict + cleaned_extra_body: dict[str, object] = {} # mutable-ok: building cleaned extra_body dict + extra_body_dict: dict[object, object] = value # pyright: ignore[reportUnknownVariableType] # mutable-ok: reading from extra_body for k, v in extra_body_dict.items(): if isinstance(k, str) and (k in LITELLM_INTERNAL_PARAM_NAMES or k.startswith("_litellm_")): continue