langchain-ai/langchain · error · ValueError

The number of tool_outputs ({len(tool_outputs)}) must match

Error message

The number of tool_outputs ({len(tool_outputs)}) must match the number of tool_calls ({len(openai_tool_calls)}). Got {len(tool_outputs)} output(s) for {len(openai_tool_calls)} tool call(s).

What it means

Error "The number of tool_outputs ({len(tool_outputs)}) must match the number of tool_calls ({len(openai_tool_calls)}). Got {len(tool_outputs)} output(s) for {len(openai_tool_calls)} tool call(s)." thrown in langchain-ai/langchain.

Source

Thrown at libs/core/langchain_core/utils/function_calling.py:722

                # of the Pydantic model. This is implicit in the API right now,
                # and will be improved over time.
                "name": tool_call.__class__.__name__,
                "arguments": tool_call.model_dump_json(),
            },
        }
        for tool_call in tool_calls
    ]

    messages.append(
        AIMessage(content="", additional_kwargs={"tool_calls": openai_tool_calls})
    )
    if tool_outputs is not None and len(tool_outputs) != len(openai_tool_calls):
        msg = (
            f"The number of tool_outputs ({len(tool_outputs)}) must match the number "
            f"of tool_calls ({len(openai_tool_calls)}). Got {len(tool_outputs)} "
            f"output(s) for {len(openai_tool_calls)} tool call(s)."
        )
        raise ValueError(msg)
    tool_outputs = tool_outputs or ["You have correctly called this tool."] * len(
        openai_tool_calls
    )
    for output, tool_call_dict in zip(tool_outputs, openai_tool_calls, strict=False):
        messages.append(ToolMessage(content=output, tool_call_id=tool_call_dict["id"]))

    if ai_response:
        messages.append(AIMessage(content=ai_response))
    return messages


_MIN_DOCSTRING_BLOCKS = 2


def _parse_google_docstring(
    docstring: str | None,
    args: list[str],
    *,

View on GitHub (pinned to e32fa9a52e)

Solutions

  1. Provide exactly one tool_output per tool_call, in matching order.
  2. Check the model response: if it emitted N tool calls, supply N tool outputs.

Example fix

tool_outputs = [result_for_call_0, result_for_call_1]  # same length as tool_calls

When it happens

Trigger: Raised when the list of tool_outputs supplied (e.g. for submitting tool results) does not match the number of tool_calls issued by the model.

Common situations: See trigger scenarios.


AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14). Data as JSON: /api/errors/7743198ec66d60a8. Report an issue: GitHub.