sgl-project/sglang · error · ValueError

No call message found for {call_id}

Error message

No call message found for {call_id}

What it means

In harmony_utils.parse_response_input, a 'function_call_output' response item references a call_id for which no matching ResponseFunctionToolCall exists in the prior context. The parser needs the paired call message (for the tool name) to build the harmony TOOL message, so an orphaned tool output is a hard error.

Source

Thrown at python/sglang/srt/entrypoints/harmony_utils.py:184

                c for c in content if c.get("type") in ("text", "input_text")
            ]
            contents = [
                TextContent(text=(text_prefix if i == 0 else "") + c.get("text", ""))
                for i, c in enumerate(text_chunks)
            ]
            msg = Message.from_role_and_contents(role, contents)
    elif response_msg["type"] == "function_call_output":
        call_id = response_msg["call_id"]
        call_response: Optional[ResponseFunctionToolCall] = None
        for prev_response in reversed(prev_responses):
            if (
                isinstance(prev_response, ResponseFunctionToolCall)
                and prev_response.call_id == call_id
            ):
                call_response = prev_response
                break
        if call_response is None:
            raise ValueError(f"No call message found for {call_id}")
        msg = Message.from_author_and_content(
            Author.new(Role.TOOL, f"functions.{call_response.name}"),
            response_msg["output"],
        )
    elif response_msg["type"] == "reasoning":
        content = response_msg["content"]
        assert len(content) == 1
        msg = Message.from_role_and_content(Role.ASSISTANT, content[0]["text"])
    elif response_msg["type"] == "function_call":
        msg = Message.from_role_and_content(Role.ASSISTANT, response_msg["arguments"])
        msg = msg.with_channel("commentary")
        msg = msg.with_recipient(f"functions.{response_msg['name']}")
        msg = msg.with_content_type("json")
    else:
        raise ValueError(f"Unknown input type: {response_msg['type']}")
    return msg

View on GitHub (pinned to 0132848349)

Solutions

  1. Ensure every function_call_output in the input history is preceded by its matching function_call item with the same call_id
  2. If trimming history, drop each tool output together with its call
  3. Regenerate the conversation from the source of truth (the original Responses API items) instead of hand-editing IDs

Example fix

# before
input = [{"type":"function_call_output","call_id":"call_1","output":"42"}]
# after
input = [
  {"type":"function_call","call_id":"call_1","name":"get_x","arguments":"{}"},
  {"type":"function_call_output","call_id":"call_1","output":"42"},
]
Defensive patterns

Strategy: validation

Validate before calling

def tool_outputs_are_paired(items):
    call_ids = {i.get("call_id") for i in items if i.get("type") == "function_call"}
    return all(i.get("call_id") in call_ids
               for i in items if i.get("type") == "function_call_output")

Type guard

def has_matching_call(items, output_item) -> bool:
    return any(
        i.get("type") == "function_call" and i.get("call_id") == output_item.get("call_id")
        for i in items
    )

Try / catch

try:
    msgs = _construct_input_messages_with_harmony(items)
except ValueError as e:
    if "No call message found" in str(e):
        items = [i for i in items if not (i.get("type") == "function_call_output" and not has_matching_call(items, i))]
        msgs = _construct_input_messages_with_harmony(items)
    else:
        raise

Prevention

When it happens

Trigger: Passing conversation history where an item with type 'function_call_output' has a call_id that doesn't match any earlier ResponseFunctionToolCall.call_id — dropped/truncated history, out-of-order items, or mismatched IDs from a client.

Common situations: Trimming old messages out of a long tool-use conversation and cutting the function_call but keeping its output; clients that regenerate call_ids; resuming sessions with truncated context windows.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/b627ffc1072e203a. Report an issue: GitHub.