diff --git a/litellm/responses/litellm_completion_transformation/transformation.py b/litellm/responses/litellm_completion_transformation/transformation.py index 35d4b8bf1ba..88875a049d1 100644 --- a/litellm/responses/litellm_completion_transformation/transformation.py +++ b/litellm/responses/litellm_completion_transformation/transformation.py @@ -2120,7 +2120,7 @@ class LiteLLMCompletionResponsesConfig: # Ensure we include any accumulated text as text blocks too return normalized_blocks if text_acc: - return "".join(text_acc) + return "\n".join(text_acc) try: # last resort: keep something meaningful for providers that require a string import json as _json diff --git a/tests/unit/responses/litellm_completion_transformation/test_function_call_output_normalization.py b/tests/unit/responses/litellm_completion_transformation/test_function_call_output_normalization.py index 3af1ef51e3e..1a0b8d34ee0 100644 --- a/tests/unit/responses/litellm_completion_transformation/test_function_call_output_normalization.py +++ b/tests/unit/responses/litellm_completion_transformation/test_function_call_output_normalization.py @@ -11,7 +11,26 @@ from litellm.responses.litellm_completion_transformation.transformation import ( ) -def test_function_call_output_list_input_text_is_converted_to_tool_string_content(): +def test_function_call_output_list_input_text_parts_reach_the_tool_message_on_separate_lines(): + out = LiteLLMCompletionResponsesConfig._transform_responses_api_tool_call_output_to_chat_completion_message( + tool_call_output={ + "type": "function_call_output", + "call_id": "call_1", + "output": [ + {"type": "input_text", "text": "Paris: 22 degrees"}, + {"type": "input_text", "text": "clear skies"}, + ], + } + ) + + assert len(out) == 1 + msg = out[0] + assert msg["role"] == "tool" + assert msg["tool_call_id"] == "call_1" + assert msg["content"] == "Paris: 22 degrees\nclear skies" + + +def test_function_call_output_text_part_whitespace_survives_the_join(): out = LiteLLMCompletionResponsesConfig._transform_responses_api_tool_call_output_to_chat_completion_message( tool_call_output={ "type": "function_call_output", @@ -23,11 +42,7 @@ def test_function_call_output_list_input_text_is_converted_to_tool_string_conten } ) - assert len(out) == 1 - msg = out[0] - assert msg["role"] == "tool" - assert msg["tool_call_id"] == "call_1" - assert msg["content"] == "hello world" + assert out[0]["content"] == "hello\n world" def test_function_call_output_string_passthrough():