langchain-ai/langgraph · error · ValueError
Expected to have a matching ToolMessage in Command.update fo
Error message
Expected to have a matching ToolMessage in Command.update for tool '{call['name']}', got: {messages_update}. Every tool call (LLM requesting to call a tool) in the message history MUST have a corresponding ToolMessage. You can fix it by modifying the tool to return {example_update}. What it means
Error "Expected to have a matching ToolMessage in Command.update for tool '{call['name']}', got: {messages_update}. Every tool call (LLM requesting to call a tool) in the message history MUST have a corresponding ToolMessage. You can fix it by modifying the tool to return {example_update}." thrown in langchain-ai/langgraph.
Source
Thrown at libs/prebuilt/langgraph/prebuilt/tool_node.py:1578
require_terminator
and updated_command.graph is None
and not has_matching_tool_message
):
example_update = (
'`Command(update={"messages": '
'[ToolMessage("Success", tool_call_id=tool_call_id), ...]}, ...)`'
if input_type == "dict"
else "`Command(update="
'[ToolMessage("Success", tool_call_id=tool_call_id), ...], ...)`'
)
msg = (
"Expected to have a matching ToolMessage in Command.update "
f"for tool '{call['name']}', got: {messages_update}. "
"Every tool call (LLM requesting to call a tool) "
"in the message history MUST have a corresponding ToolMessage. "
f"You can fix it by modifying the tool to return {example_update}."
)
raise ValueError(msg)
return updated_command
def tools_condition(
state: list[AnyMessage] | dict[str, Any] | BaseModel,
messages_key: str = "messages",
) -> Literal["tools", "__end__"]:
"""Conditional routing function for tool-calling workflows.
This utility function implements the standard conditional logic for ReAct-style
agents: if the last `AIMessage` contains tool calls, route to the tool execution
node; otherwise, end the workflow. This pattern is fundamental to most tool-calling
agent architectures.
The function handles multiple state formats commonly used in LangGraph applications,
making it flexible for different graph designs while maintaining consistent behavior.
Args:View on GitHub (pinned to 38031739e5)
When it happens
Trigger: Thrown at libs/prebuilt/langgraph/prebuilt/tool_node.py:1578 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of langchain-ai/langgraph@38031739e5 (2026-08-26).
Data as JSON: /api/errors/8f5d8b5f2f786b36.
Report an issue: GitHub.