{"record":{"id":"8f5d8b5f2f786b36","repo":"langchain-ai/langgraph","slug":"expected-to-have-a-matching-toolmessage-in-command","errorCode":null,"errorMessage":"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}.","messagePattern":"Expected to have a matching ToolMessage in Command\\.update for tool '(.+?)', got: (.+?)\\. 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 (.+?)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/prebuilt/langgraph/prebuilt/tool_node.py","lineNumber":1578,"sourceCode":"            require_terminator\n            and updated_command.graph is None\n            and not has_matching_tool_message\n        ):\n            example_update = (\n                '`Command(update={\"messages\": '\n                '[ToolMessage(\"Success\", tool_call_id=tool_call_id), ...]}, ...)`'\n                if input_type == \"dict\"\n                else \"`Command(update=\"\n                '[ToolMessage(\"Success\", tool_call_id=tool_call_id), ...], ...)`'\n            )\n            msg = (\n                \"Expected to have a matching ToolMessage in Command.update \"\n                f\"for tool '{call['name']}', got: {messages_update}. \"\n                \"Every tool call (LLM requesting to call a tool) \"\n                \"in the message history MUST have a corresponding ToolMessage. \"\n                f\"You can fix it by modifying the tool to return {example_update}.\"\n            )\n            raise ValueError(msg)\n        return updated_command\n\n\ndef tools_condition(\n    state: list[AnyMessage] | dict[str, Any] | BaseModel,\n    messages_key: str = \"messages\",\n) -> Literal[\"tools\", \"__end__\"]:\n    \"\"\"Conditional routing function for tool-calling workflows.\n\n    This utility function implements the standard conditional logic for ReAct-style\n    agents: if the last `AIMessage` contains tool calls, route to the tool execution\n    node; otherwise, end the workflow. This pattern is fundamental to most tool-calling\n    agent architectures.\n\n    The function handles multiple state formats commonly used in LangGraph applications,\n    making it flexible for different graph designs while maintaining consistent behavior.\n\n    Args:","sourceCodeStart":1560,"sourceCodeEnd":1596,"githubUrl":"https://github.com/langchain-ai/langgraph/blob/38031739e551638e373fb553453256c23feeb41f/libs/prebuilt/langgraph/prebuilt/tool_node.py#L1560-L1596","documentation":"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.","triggerScenarios":"Thrown at libs/prebuilt/langgraph/prebuilt/tool_node.py:1578 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"38031739e551638e373fb553453256c23feeb41f","analyzedAt":"2026-08-26T18:02:49.312Z","schemaVersion":2},"datasetVersion":"2026-08-26T21:11:00.512Z"}