From cca41c9ce341963d8367778e57dcba61374a625f Mon Sep 17 00:00:00 2001 From: mateo Date: Sun, 18 Oct 2026 13:09:09 +0000 Subject: [PATCH] refactor(types): revert anthropic chat response seam Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- litellm/llms/anthropic/chat/transformation.py | 3 +-- .../test_custom_prompt_management.py | 22 +++---------------- .../test_pattern_match_deployments.py | 18 +-------------- 3 files changed, 5 insertions(+), 38 deletions(-) diff --git a/litellm/llms/anthropic/chat/transformation.py b/litellm/llms/anthropic/chat/transformation.py index 859b3ddd2f0..38af6e7998b 100644 --- a/litellm/llms/anthropic/chat/transformation.py +++ b/litellm/llms/anthropic/chat/transformation.py @@ -3100,7 +3100,7 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig): ## RESPONSE OBJECT try: - completion_response: Final = _COMPLETION_RESPONSE.validate_python(raw_response.json()) + completion_response: Final = raw_response.json() except Exception as e: response_headers: Final = getattr(raw_response, "headers", None) raise AnthropicError( @@ -3186,7 +3186,6 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig): _DECODED_JSON: Final = TypeAdapter(object) -_COMPLETION_RESPONSE: Final = TypeAdapter(dict[str, object], config=ConfigDict(strict=True)) _REQUEST_TOOLS: Final = TypeAdapter(tuple[Mapping[str, object], ...]) diff --git a/tests/unit/integrations/test_custom_prompt_management.py b/tests/unit/integrations/test_custom_prompt_management.py index 0255e12acad..0bf2063a98d 100644 --- a/tests/unit/integrations/test_custom_prompt_management.py +++ b/tests/unit/integrations/test_custom_prompt_management.py @@ -55,22 +55,6 @@ class TestCustomPromptManagement(CustomPromptManagement): return model, messages, non_default_params -def _anthropic_chat_response() -> httpx.Response: - return httpx.Response( - 200, - json={ - "id": "msg_123", - "type": "message", - "role": "assistant", - "content": [{"type": "text", "text": "Hello"}], - "model": "claude-3-5-sonnet", - "stop_reason": "end_turn", - "stop_sequence": None, - "usage": {"input_tokens": 1, "output_tokens": 1}, - }, - ) - - @pytest.mark.asyncio async def test_custom_prompt_management_with_prompt_id(monkeypatch): custom_prompt_management = TestCustomPromptManagement() @@ -78,7 +62,7 @@ async def test_custom_prompt_management_with_prompt_id(monkeypatch): # Mock AsyncHTTPHandler.post method client = AsyncHTTPHandler() - with patch.object(client, "post", return_value=_anthropic_chat_response()) as mock_post: + with patch.object(client, "post", return_value=MagicMock()) as mock_post: await litellm.acompletion( model="anthropic/claude-3-5-sonnet", messages=[{"role": "user", "content": "Hello, how are you?"}], @@ -106,7 +90,7 @@ async def test_custom_prompt_management_with_prompt_id_and_prompt_variables(): # Mock AsyncHTTPHandler.post method client = AsyncHTTPHandler() - with patch.object(client, "post", return_value=_anthropic_chat_response()) as mock_post: + with patch.object(client, "post", return_value=MagicMock()) as mock_post: await litellm.acompletion( model="anthropic/claude-3-5-sonnet", messages=[], @@ -135,7 +119,7 @@ async def test_custom_prompt_management_without_prompt_id(): # Mock AsyncHTTPHandler.post method client = AsyncHTTPHandler() - with patch.object(client, "post", return_value=_anthropic_chat_response()) as mock_post: + with patch.object(client, "post", return_value=MagicMock()) as mock_post: await litellm.acompletion( model="anthropic/claude-3-5-sonnet", messages=[{"role": "user", "content": "Hello, how are you?"}], diff --git a/tests/unit/router_utils/test_pattern_match_deployments.py b/tests/unit/router_utils/test_pattern_match_deployments.py index 227df270675..01af021112b 100644 --- a/tests/unit/router_utils/test_pattern_match_deployments.py +++ b/tests/unit/router_utils/test_pattern_match_deployments.py @@ -317,23 +317,7 @@ def test_router_pattern_match_e2e(): ] ) - with patch.object( - client, - "post", - return_value=httpx.Response( - 200, - json={ - "id": "msg_123", - "type": "message", - "role": "assistant", - "content": [{"type": "text", "text": "Hello"}], - "model": "claude-3-5-sonnet", - "stop_reason": "end_turn", - "stop_sequence": None, - "usage": {"input_tokens": 1, "output_tokens": 1}, - }, - ), - ) as mock_post: + with patch.object(client, "post", new=MagicMock()) as mock_post: router.completion( model="llmengine/my-custom-model",