From f4cf2fce55b77c3c56d41c677f76fa7fc50cf80e Mon Sep 17 00:00:00 2001 From: Ishaan Jaffer Date: Sat, 21 Feb 2026 10:00:44 -0800 Subject: [PATCH] fix(mypy): suppress typeddict-item error for tracing_kw expansion --- .../litellm_content_filter/content_filter.py | 57 ++++++++++++++----- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/content_filter.py b/litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/content_filter.py index 16c46a76ccd..201500c8bac 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/content_filter.py +++ b/litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/content_filter.py @@ -10,8 +10,19 @@ import json import os import re from datetime import datetime -from typing import (TYPE_CHECKING, Any, AsyncGenerator, Dict, List, Literal, - Optional, Pattern, Tuple, Union, cast) +from typing import ( + TYPE_CHECKING, + Any, + AsyncGenerator, + Dict, + List, + Literal, + Optional, + Pattern, + Tuple, + Union, + cast, +) import yaml from fastapi import HTTPException @@ -20,22 +31,37 @@ from litellm import Router from litellm._logging import verbose_proxy_logger from litellm.integrations.custom_guardrail import CustomGuardrail from litellm.proxy._types import UserAPIKeyAuth -from litellm.types.utils import (GenericGuardrailAPIInputs, GuardrailStatus, - GuardrailTracingDetail, ModelResponseStream) +from litellm.types.utils import ( + GenericGuardrailAPIInputs, + GuardrailStatus, + GuardrailTracingDetail, + ModelResponseStream, +) if TYPE_CHECKING: from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj -from litellm.types.guardrails import (BlockedWord, ContentFilterAction, - ContentFilterPattern, - GuardrailEventHooks, Mode) +from litellm.types.guardrails import ( + BlockedWord, + ContentFilterAction, + ContentFilterPattern, + GuardrailEventHooks, + Mode, +) from litellm.types.proxy.guardrails.guardrail_hooks.litellm_content_filter import ( - BlockedWordDetection, CategoryKeywordDetection, CompetitorIntentDetection, - CompetitorIntentResult, ContentFilterCategoryConfig, - ContentFilterDetection, PatternDetection) + BlockedWordDetection, + CategoryKeywordDetection, + CompetitorIntentDetection, + CompetitorIntentResult, + ContentFilterCategoryConfig, + ContentFilterDetection, + PatternDetection, +) -from .competitor_intent import (AirlineCompetitorIntentChecker, - BaseCompetitorIntentChecker) +from .competitor_intent import ( + AirlineCompetitorIntentChecker, + BaseCompetitorIntentChecker, +) from .patterns import PATTERN_EXTRA_CONFIG, get_compiled_pattern MAX_KEYWORD_VALUE_GAP_WORDS = 1 @@ -1702,7 +1728,7 @@ class ContentFilterGuardrail(CustomGuardrail): end_time=datetime.now().timestamp(), duration=(datetime.now() - start_time).total_seconds(), masked_entity_count=masked_entity_count, - tracing_detail=GuardrailTracingDetail(**tracing_kw), + tracing_detail=GuardrailTracingDetail(**tracing_kw), # type: ignore[typeddict-item] ) async def apply_guardrail( @@ -1878,7 +1904,8 @@ class ContentFilterGuardrail(CustomGuardrail): @staticmethod def get_config_model(): - from litellm.types.proxy.guardrails.guardrail_hooks.litellm_content_filter import \ - LitellmContentFilterGuardrailConfigModel + from litellm.types.proxy.guardrails.guardrail_hooks.litellm_content_filter import ( + LitellmContentFilterGuardrailConfigModel, + ) return LitellmContentFilterGuardrailConfigModel