From 5a76aada3c14ab3ca77648acf4088685a16f8a2f Mon Sep 17 00:00:00 2001 From: Alexsander Hamir Date: Sat, 20 Dec 2025 10:27:58 -0800 Subject: [PATCH] [Fix] CI/CD - responses_api_testing (#18295) --- .../transformation.py | 17 ++++++++++++++++- .../test_anthropic_responses_api.py | 15 +++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/litellm/responses/litellm_completion_transformation/transformation.py b/litellm/responses/litellm_completion_transformation/transformation.py index af0847e3e24..ad910c9cd97 100644 --- a/litellm/responses/litellm_completion_transformation/transformation.py +++ b/litellm/responses/litellm_completion_transformation/transformation.py @@ -321,7 +321,22 @@ class LiteLLMCompletionResponsesConfig: # If we had session messages but they got filtered out, # restore them combined_messages = session_messages - # If both are empty, we'll let it fail with a proper error message + else: + # Both are empty - this likely means function_call_output had empty/invalid call_id + # Provide a helpful error message + import litellm + raise litellm.BadRequestError( + message=( + f"Unable to create messages for completion request. " + f"This can happen when: " + f"1) Using previous_response_id without a session database, AND " + f"2) Input contains only function_call_output with empty or invalid call_id. " + f"Please ensure function_call_output has a valid call_id from a previous response. " + f"Original request: previous_response_id={previous_response_id}" + ), + model=litellm_completion_request.get("model", ""), + llm_provider=litellm_completion_request.get("custom_llm_provider", ""), + ) litellm_completion_request["messages"] = combined_messages litellm_completion_request["litellm_trace_id"] = chat_completion_session.get( diff --git a/tests/llm_responses_api_testing/test_anthropic_responses_api.py b/tests/llm_responses_api_testing/test_anthropic_responses_api.py index df818ce5c7d..5df1045b7c0 100644 --- a/tests/llm_responses_api_testing/test_anthropic_responses_api.py +++ b/tests/llm_responses_api_testing/test_anthropic_responses_api.py @@ -90,11 +90,18 @@ def test_multiturn_tool_calls(): # Get the response ID and tool call ID from the response response_id = response.id - tool_call_id = "" + tool_call_id = None for item in response.output: - if 'type' in item and item['type'] == 'function_call': - tool_call_id = item['call_id'] - break + if hasattr(item, 'type') and item.type == 'function_call': + tool_call_id = getattr(item, 'call_id', None) + if tool_call_id: + break + + # Validate that we got a tool call with a valid call_id + if not tool_call_id: + raise AssertionError( + f"Expected a function_call with a valid call_id in response.output, but got: {response.output}" + ) # Use await with asyncio.run for the async function follow_up_response = litellm.responses(