From cecc20eebae549eae7551ea03ea7cbeba37dca54 Mon Sep 17 00:00:00 2001 From: Tai An Date: Wed, 27 May 2026 18:14:38 -0700 Subject: [PATCH] fix(opentelemetry): use separate hashable_guardrail_mode to satisfy mypy The previous reassignment of guardrail_mode to a tuple tripped mypy because the variable inferred type from .get() is GuardrailEventHooks | list[GuardrailEventHooks] | GuardrailMode | None, which does not include tuple. Use a separately-named Any-typed binding for the hashable form passed to _emit_once, preserving the original runtime fix and keeping mypy green. --- litellm/integrations/opentelemetry.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/litellm/integrations/opentelemetry.py b/litellm/integrations/opentelemetry.py index 4333e33cdd9..9ca03c0c169 100644 --- a/litellm/integrations/opentelemetry.py +++ b/litellm/integrations/opentelemetry.py @@ -1570,14 +1570,17 @@ class OpenTelemetry(OTELGenAISemconvMixin, CustomLogger): # (e.g. ``mode: ["pre_call", "post_call"]``); ``_emit_once`` # requires hashable scope parts, so normalize lists to tuples. guardrail_mode = guardrail_information.get("guardrail_mode") - if isinstance(guardrail_mode, list): - guardrail_mode = tuple(guardrail_mode) + hashable_guardrail_mode: Any = ( + tuple(guardrail_mode) + if isinstance(guardrail_mode, list) + else guardrail_mode + ) if not self._emit_once( kwargs, "guardrail", guardrail_information.get("guardrail_name"), start_time_float, - guardrail_mode, + hashable_guardrail_mode, ): continue