litellm - 💡(How to fix) Fix Responses API: function_call not converted to tool_calls in mixed content assistant messages [1 pull requests]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

When a Responses API request contains an assistant message with BOTH text and function_call content items, the function_call is not properly converted to the Chat Completions tool_calls array during the Responses→Chat transformation. This causes a "Missing corresponding tool call for tool response message" error when the corresponding function_call_output is processed.

Error Message

Missing corresponding tool call for tool response message. 
Received - message={'role': 'tool', 'content': 'result', 'tool_call_id': 'call_good'}, 
last_message_with_tool_calls={'role': 'assistant', 'content': [{'type': 'text', 'text': 'ok'}]}

Root Cause

In the Responses API → Chat Completions request transformation, mixed-content assistant messages (those containing both text and function_call content items) are not properly handled. The function_call content item appears to be stripped without being converted to a tool_calls entry, leaving orphan function_call_output tool results that fail validation in downstream providers (especially Gemini).

Fix Action

Fixed

Code Example

Missing corresponding tool call for tool response message. 
Received - message={'role': 'tool', 'content': 'result', 'tool_call_id': 'call_good'}, 
last_message_with_tool_calls={'role': 'assistant', 'content': [{'type': 'text', 'text': 'ok'}]}

---

{
  "model": "gpt-5.3-codex",
  "input": [
    {
      "role": "assistant",
      "content": [
        {"type": "text", "text": "ok"},
        {"type": "function_call", "id": "call_good", "name": "test", "arguments": "{}"}
      ]
    },
    {
      "type": "function_call_output",
      "call_id": "call_good",
      "output": "result"
    },
    {
      "role": "user",
      "content": [{"type": "input_text", "text": "continue"}]
    }
  ],
  "modalities": ["text"]
}
RAW_BUFFERClick to expand / collapse

Description

When a Responses API request contains an assistant message with BOTH text and function_call content items, the function_call is not properly converted to the Chat Completions tool_calls array during the Responses→Chat transformation. This causes a "Missing corresponding tool call for tool response message" error when the corresponding function_call_output is processed.

Root Cause

In the Responses API → Chat Completions request transformation, mixed-content assistant messages (those containing both text and function_call content items) are not properly handled. The function_call content item appears to be stripped without being converted to a tool_calls entry, leaving orphan function_call_output tool results that fail validation in downstream providers (especially Gemini).

Error

Missing corresponding tool call for tool response message. 
Received - message={'role': 'tool', 'content': 'result', 'tool_call_id': 'call_good'}, 
last_message_with_tool_calls={'role': 'assistant', 'content': [{'type': 'text', 'text': 'ok'}]}

Steps to Reproduce

Send a /v1/responses request with this input:

{
  "model": "gpt-5.3-codex",
  "input": [
    {
      "role": "assistant",
      "content": [
        {"type": "text", "text": "ok"},
        {"type": "function_call", "id": "call_good", "name": "test", "arguments": "{}"}
      ]
    },
    {
      "type": "function_call_output",
      "call_id": "call_good",
      "output": "result"
    },
    {
      "role": "user",
      "content": [{"type": "input_text", "text": "continue"}]
    }
  ],
  "modalities": ["text"]
}

Expected: 200 OK with a response Actual: 500 error (after 2 retries) with the orphan tool error above

Why This Matters

This pattern can occur in real-world usage when Codex or other Responses API clients replay conversation history that includes both text and tool calls from a previous assistant turn.

Environment

  • LiteLLM version: main-latest (ghcr.io/berriai/litellm:main-latest)
  • Backend: gemini/gemini-2.5-flash
  • Python: 3.13

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING