diff --git a/litellm/llms/anthropic/messages/native/transformation.py b/litellm/llms/anthropic/messages/native/transformation.py index 29b2beb1d7c..3a8cb8b5b4c 100644 --- a/litellm/llms/anthropic/messages/native/transformation.py +++ b/litellm/llms/anthropic/messages/native/transformation.py @@ -231,14 +231,13 @@ class AnthropicMessagesConfig(BaseAnthropicMessagesConfig): return system_param def _strip_beta_gated_system_turns( - self, messages: Sequence[object], model: str, drop_params: object - ) -> tuple[Mapping[str, object], ...]: - validated: Final = _MESSAGE_MAPPINGS.validate_python(messages) + self, messages: Sequence[Mapping[str, object]], model: str, drop_params: object + ) -> Sequence[Mapping[str, object]]: if not has_beta_headers_config(self._resolved_provider): - return validated - gated: Final = strip_beta_gated_system_messages(validated, frozenset(), drop_params=drop_params) + return messages + gated: Final = strip_beta_gated_system_messages(messages, frozenset(), drop_params=drop_params) log_beta_gated_strips(gated.stripped, model=model, provider=self._resolved_provider) - return _MESSAGE_MAPPINGS.validate_python(gated.messages) if gated.stripped else validated + return _MESSAGE_MAPPINGS.validate_python(gated.messages) if gated.stripped else messages def _normalize_system_role_messages( self, anthropic_messages_request: dict, model: str, drop_params: object diff --git a/tests/unit/llms/vertex_ai/vertex_ai_partner_models/anthropic/test_vertex_ai_partner_models_anthropic_messages_config.py b/tests/unit/llms/vertex_ai/vertex_ai_partner_models/anthropic/test_vertex_ai_partner_models_anthropic_messages_config.py index 47c87c7e850..48611f5715d 100644 --- a/tests/unit/llms/vertex_ai/vertex_ai_partner_models/anthropic/test_vertex_ai_partner_models_anthropic_messages_config.py +++ b/tests/unit/llms/vertex_ai/vertex_ai_partner_models/anthropic/test_vertex_ai_partner_models_anthropic_messages_config.py @@ -851,6 +851,20 @@ class TestVertexAnthropicMidConversationSystem: {"type": "text", "text": "Cite sources."}, ] + @pytest.mark.parametrize("drop_params", (False, True)) + def test_unsupported_model_sends_a_non_object_message_on_for_the_provider_to_reject( + self, local_model_cost_map, local_beta_headers_config, drop_params + ): + messages: Final = [{"role": "user", "content": "hi"}, "oops"] + result: Final = VertexAIPartnerModelsAnthropicMessagesConfig().transform_anthropic_messages_request( + model="claude-sonnet-4-6", + messages=list(messages), + anthropic_messages_optional_request_params={"max_tokens": 64}, + litellm_params=GenericLiteLLMParams(drop_params=drop_params), + headers={}, + ) + assert result["messages"] == messages + def test_unsupported_model_converts_mid_conversation_system_in_place(self, local_model_cost_map): messages = [ {"role": "user", "content": "read the file"},