The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
refactor: type the buffered stream rewrite helpers without Any
mateo-berri113350756595
diff --git a/litellm/llms/anthropic/chat/guardrail_translation/handler.py b/litellm/llms/anthropic/chat/guardrail_translation/handler.pyindex cbbccac17f3..6f966ae1a02 100644--- a/litellm/llms/anthropic/chat/guardrail_translation/handler.py+++ b/litellm/llms/anthropic/chat/guardrail_translation/handler.py@@ -13,7 +13,7 @@ Pattern Overview:"""import json-from collections.abc import Mapping, Sequence+from collections.abc import Mapping, MutableSequence, Sequencefrom copy import deepcopyfrom dataclasses import dataclassfrom itertools import chain, repeat@@ -1262,7 +1262,7 @@ class AnthropicMessagesHandler(BaseTranslation):@staticmethoddef _write_ended_stream_text_rewrite(- responses_so_far: list[Any], # mutable-ok: rewrites the caller's buffered chunks in place+ responses_so_far: MutableSequence[object], # mutable-ok: rewrites the caller's buffered chunks in placerewritten_text: str,) -> None:"""Deliver an ended-stream guardrail text rewrite by rewriting the@@ -1284,7 +1284,7 @@ class AnthropicMessagesHandler(BaseTranslation):@classmethoddef _write_ended_stream_tool_call_rewrites(cls,- responses_so_far: list[Any], # mutable-ok: rewrites the caller's buffered chunks in place+ responses_so_far: MutableSequence[object], # mutable-ok: rewrites the caller's buffered chunks in place*,pre_guardrail_tool_calls: tuple[_ToolCallShape, ...],post_guardrail_tool_calls: tuple[_ToolCallShape, ...],@@ -1346,7 +1346,7 @@ class AnthropicMessagesHandler(BaseTranslation):@staticmethoddef _rewrite_ended_stream_events(- responses_so_far: list[Any], # mutable-ok: rewrites the caller's buffered chunks in place+ responses_so_far: MutableSequence[object], # mutable-ok: rewrites the caller's buffered chunks in placerewrite_event: _SSEEventRewriter,) -> None:"""Replace every buffered event ``rewrite_event`` returns a rewrite for, indiff --git a/tests/test_litellm/llms/openai/responses/test_openai_responses_guardrail_handler.py b/tests/test_litellm/llms/openai/responses/test_openai_responses_guardrail_handler.pyindex fa1e969b277..6ed4ec6618f 100644--- a/tests/test_litellm/llms/openai/responses/test_openai_responses_guardrail_handler.py+++ b/tests/test_litellm/llms/openai/responses/test_openai_responses_guardrail_handler.py@@ -17,6 +17,7 @@ from fastapi import HTTPExceptionfrom openai.types.responses import ResponseFunctionToolCallfrom litellm.integrations.custom_guardrail import CustomGuardrail+from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObjfrom litellm.llms import get_guardrail_translation_mappingfrom litellm.llms.openai.responses.guardrail_translation.handler import (OpenAIResponsesHandler,@@ -1238,7 +1239,7 @@ class TestOpenAIResponsesHandlerStreamingOutputProcessing:inputs: GenericGuardrailAPIInputs,request_data: dict,input_type: Literal["request", "response"],- logging_obj: Optional[Any] = None,+ logging_obj: LiteLLMLoggingObj | None = None,) -> GenericGuardrailAPIInputs:tool_calls = [{**tool_call, "function": {**tool_call["function"], "arguments": '{"fruit": "[MASKED]"}'}}