diff --git a/litellm/types/llms/anthropic.py b/litellm/types/llms/anthropic.py index 6aa0be36aa8..b394b07f22a 100644 --- a/litellm/types/llms/anthropic.py +++ b/litellm/types/llms/anthropic.py @@ -1,4 +1,4 @@ -from collections.abc import Iterable, Sequence +from collections.abc import Iterable, Mapping, Sequence from enum import Enum from typing import Any, Final, Literal, TypeAlias @@ -410,7 +410,7 @@ class AnthropicMessagesRequestOptionalParams(TypedDict, total=False): output_config: AnthropicOutputConfig | None # Configuration for Claude's output behavior cache_control: dict[str, Any] | None # Automatic prompt caching reasoning_effort: str | None - safeguards: ReadOnly[list[dict[str, object]] | None] + safeguards: ReadOnly[Sequence[Mapping[str, object]] | None] class AnthropicMessagesRequest(AnthropicMessagesRequestOptionalParams, total=False): @@ -530,7 +530,7 @@ class AnthropicStopDetails(TypedDict, total=False): class MessageDelta(TypedDict, total=False): stop_reason: str | None stop_details: ReadOnly[AnthropicStopDetails] - safeguard_results: ReadOnly[list[dict[str, object]]] + safeguard_results: ReadOnly[Sequence[Mapping[str, object]]] class ServerToolUsage(TypedDict, total=False): @@ -601,7 +601,7 @@ class MessageChunk(TypedDict, total=False): stop_reason: str | None stop_sequence: str | None usage: UsageDelta - safeguard_results: ReadOnly[list[dict[str, object]]] + safeguard_results: ReadOnly[Sequence[Mapping[str, object]]] class MessageStartBlock(TypedDict): diff --git a/litellm/types/llms/anthropic_messages/anthropic_response.py b/litellm/types/llms/anthropic_messages/anthropic_response.py index 1d4c3cdc864..8314248ee07 100644 --- a/litellm/types/llms/anthropic_messages/anthropic_response.py +++ b/litellm/types/llms/anthropic_messages/anthropic_response.py @@ -1,3 +1,4 @@ +from collections.abc import Mapping, Sequence from typing import Any, Literal, TypeAlias from typing_extensions import NotRequired, ReadOnly, TypedDict @@ -97,4 +98,4 @@ class AnthropicMessagesResponse(TypedDict, total=False): type: Literal["message"] | None usage: AnthropicUsage | None context_management: NotRequired[ContextManagementResponse] - safeguard_results: NotRequired[ReadOnly[list[dict[str, object]]]] + safeguard_results: NotRequired[ReadOnly[Sequence[Mapping[str, object]]]] diff --git a/litellm/types/llms/bedrock.py b/litellm/types/llms/bedrock.py index 54593b63245..9514bca2fcd 100644 --- a/litellm/types/llms/bedrock.py +++ b/litellm/types/llms/bedrock.py @@ -1,5 +1,5 @@ import json -from collections.abc import Sequence +from collections.abc import Mapping, Sequence from enum import Enum from typing import TYPE_CHECKING, Any, Final, Literal, TypeAlias @@ -1215,7 +1215,7 @@ class BedrockInvokeAnthropicMessagesRequest(TypedDict, total=False): thinking: dict metadata: dict output_config: dict - safeguards: list + safeguards: ReadOnly[Sequence[Mapping[str, object]]] # `context_management` is allowed for Bedrock InvokeModel only when it # carries `compact_20260112` edits paired with the `compact-2026-01-12` diff --git a/tests/test_litellm/llms/anthropic/experimental_pass_through/messages/test_anthropic_experimental_pass_through_messages_handler.py b/tests/test_litellm/llms/anthropic/experimental_pass_through/messages/test_anthropic_experimental_pass_through_messages_handler.py index d92236ba264..7f21b025ed7 100644 --- a/tests/test_litellm/llms/anthropic/experimental_pass_through/messages/test_anthropic_experimental_pass_through_messages_handler.py +++ b/tests/test_litellm/llms/anthropic/experimental_pass_through/messages/test_anthropic_experimental_pass_through_messages_handler.py @@ -1627,7 +1627,9 @@ async def test_anthropic_messages_forwards_safeguards_and_dangerous_tool_use_bet safeguards, safeguard_results = _claude_code_auto_mode_request() captured: dict[str, object] = {} - with patch.object(VertexBase, "_ensure_access_token", return_value=("test-token", "test-project")): + with patch.object( # test-quality-ok: the GCP token exchange runs before the faked HTTP boundary + VertexBase, "_ensure_access_token", return_value=("test-token", "test-project") + ): response = await handler.anthropic_messages( max_tokens=16, messages=[{"role": "user", "content": "hi"}],