diff --git a/tests/e2e/llm_translation/test_bedrock_native_e2e.py b/tests/e2e/llm_translation/test_bedrock_native_e2e.py index 425d8b9b74a..95720bcace2 100644 --- a/tests/e2e/llm_translation/test_bedrock_native_e2e.py +++ b/tests/e2e/llm_translation/test_bedrock_native_e2e.py @@ -210,8 +210,8 @@ class TestBedrockNative: def test_bedrock_json_schema_response_exposes_text_before_json_tool_call( self, proxy: ProxyClient, resources: ResourceManager, sdk: SdkClients ) -> None: - model = f"e2e-bedrock-json-mode-preamble-{unique_marker()}" - model_id = proxy.create_model( + model: Final = f"e2e-bedrock-json-mode-preamble-{unique_marker()}" + model_id: Final = proxy.create_model( model, LiteLLMParamsBody( model=BEDROCK_JSON_SCHEMA_BACKEND, diff --git a/tests/unit/llms/anthropic/chat/test_anthropic_chat_transformation.py b/tests/unit/llms/anthropic/chat/test_anthropic_chat_transformation.py index 1c748f0c83d..09933605ade 100644 --- a/tests/unit/llms/anthropic/chat/test_anthropic_chat_transformation.py +++ b/tests/unit/llms/anthropic/chat/test_anthropic_chat_transformation.py @@ -9756,6 +9756,14 @@ def test_json_mode_text_without_tool_call_is_unchanged(): assert message.tool_calls is None assert "json_mode_preamble_text" not in (message.provider_specific_fields or {}) + preamble: Final = "Let me answer the question. " + json_result: Final = _transform_json_mode_body( + {**body, "content": [{"type": "text", "text": preamble}, *body["content"]]} + ) + json_message: Final = json_result.choices[0].message + assert json_message.content == '{"answer": "Hello"}' + assert json_message.provider_specific_fields["json_mode_preamble_text"] == preamble + def test_json_mode_with_a_real_tool_keeps_mixed_response_behavior(): preamble: Final = "I will look up the details. " @@ -9778,6 +9786,13 @@ def test_json_mode_with_a_real_tool_keeps_mixed_response_behavior(): assert message.tool_calls[0].function.arguments == '{"location": "San Francisco"}' assert "json_mode_preamble_text" not in (message.provider_specific_fields or {}) + json_result: Final = _transform_json_mode_body( + {**body, "content": [{"type": "text", "text": preamble}, *body["content"]]} + ) + json_message: Final = json_result.choices[0].message + assert json_message.content == '{"answer": "Hello"}' + assert json_message.provider_specific_fields["json_mode_preamble_text"] == preamble + def test_non_dict_upstream_body_still_transforms_without_refusal_fields() -> None: result = AnthropicConfig().transform_parsed_response( diff --git a/tests/unit/llms/bedrock/chat/test_converse_transformation.py b/tests/unit/llms/bedrock/chat/test_converse_transformation.py index f89ca376e47..fcdddb6daac 100644 --- a/tests/unit/llms/bedrock/chat/test_converse_transformation.py +++ b/tests/unit/llms/bedrock/chat/test_converse_transformation.py @@ -6761,7 +6761,7 @@ def _transform_json_mode_content_blocks(content: list[dict[str, object]]) -> Mod return json.dumps(response_json) return AmazonConverseConfig()._transform_response( - model="bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0", + model="bedrock/us.anthropic.claude-haiku-5-5", response=MockResponse(), model_response=ModelResponse(), stream=False, @@ -6795,7 +6795,7 @@ def test_bedrock_json_mode_preserves_nonblank_text_before_json_tool_call(): def test_bedrock_json_mode_omits_whitespace_only_preamble(): - result: Final = _transform_json_mode_content_blocks( + whitespace_result: Final = _transform_json_mode_content_blocks( [ {"text": " \n\t"}, { @@ -6808,9 +6808,25 @@ def test_bedrock_json_mode_omits_whitespace_only_preamble(): ] ) - message: Final = result.choices[0].message - assert message.content == '{"answer": 42}' - assert "json_mode_preamble_text" not in (message.provider_specific_fields or {}) + whitespace_message: Final = whitespace_result.choices[0].message + assert whitespace_message.content == '{"answer": 42}' + assert "json_mode_preamble_text" not in (whitespace_message.provider_specific_fields or {}) + + preamble: Final = "Here is the answer. " + nonblank_result: Final = _transform_json_mode_content_blocks( + [ + {"text": preamble}, + { + "toolUse": { + "toolUseId": "tooluse_json_001", + "name": "json_tool_call", + "input": {"answer": 42}, + } + }, + ] + ) + nonblank_message: Final = nonblank_result.choices[0].message + assert nonblank_message.provider_specific_fields["json_mode_preamble_text"] == preamble def test_bedrock_json_mode_preamble_preserves_reasoning_content_fields():