Repository navigation
Description
Checked other resources
- This is a bug, not a usage question.
- I added a clear and descriptive title that summarizes this issue.
- I used the GitHub search to find a similar question and didn't find it.
- I am sure that this is a bug in LangGraph rather than my code.
- The bug is not resolved by updating to the latest stable version of LangGraph (or the specific integration package).
- This is not related to the langchain-community package.
- I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.
Related Issues / PRs
- feat(prebuilt): allow ToolNode tools to return list[Command | ToolMessage] #7596 (merged): "feat(prebuilt): allow ToolNode tools to return list[Command | ToolMessage]" — the feature that introduced
_validate_tool_command_listand its "top-level or nested inside aCommand.update["messages"]" contract. The list validator does not honour that contract for two of the three shapes the sibling path accepts. - No existing issue matches: a GitHub search for the error text and for the list-return shape returns nothing relevant.
Reproduction Steps / Example Code (Python)
"""ToolNode rejects a valid list[Command] return when the terminating ToolMessage
is a dict message, or when it sits in a list-form Command.update."""
import asyncio
from unittest.mock import Mock
from langchain_core.messages import AIMessage, ToolMessage
from langchain_core.tools import BaseTool
from langgraph.prebuilt import ToolNode
from langgraph.types import Command
CALL_ID = "call-1"
MSG = [AIMessage("", tool_calls=[{"name": "t", "args": {}, "id": CALL_ID, "type": "tool_call"}])]
class T(BaseTool):
name: str = "t"
description: str = "returns a fixed value"
return_value: object = None
def _run(self, **kwargs):
return self.return_value
async def _arun(self, **kwargs):
return self.return_value
def cfg():
r = Mock()
r.store = r.context = None
r.stream_writer = lambda *a, **k: None
return {"configurable": {"__pregel_runtime": r}}
def run(label, rv, input_, async_=False):
node = ToolNode([T(return_value=rv)])
try:
if async_:
asyncio.run(node.ainvoke(input_, config=cfg()))
else:
node.invoke(input_, config=cfg())
print(f"{label:50s} -> OK")
except Exception as e: # noqa: BLE001
print(f"{label:50s} -> {type(e).__name__}: {e}")
# Terminating ToolMessage carried as a normal dict message under Command.update["messages"]
dict_msg_cmd = Command(update={"messages": [{"type": "tool", "content": "done", "tool_call_id": CALL_ID}]})
# Command.update is itself the list of messages (the shape documented for list input)
list_form_cmd = Command(update=[ToolMessage(content="done", tool_call_id=CALL_ID)])
plain_cmd = Command(update={"messages": [ToolMessage(content="done", tool_call_id=CALL_ID)]})
run("plain ToolMessage Command alone (dict input)", plain_cmd, {"messages": MSG})
run("dict-message Command alone (dict input)", dict_msg_cmd, {"messages": MSG})
run("dict-message Command in list (dict input)", [dict_msg_cmd], {"messages": MSG})
run("dict-message Command in list, async", [dict_msg_cmd], {"messages": MSG}, async_=True)
run("list-form Command alone (list input)", list_form_cmd, MSG)
run("list-form Command in list (list input)", [list_form_cmd], MSG)Error Message and Stack Trace (if applicable)
A: dict-msg Command alone (dict input) -> OK
A: dict-msg Command wrapped in list[Command] -> ValueError: Tool t returned a list with 0 messages bound to tool_call_id 'call-1';
A: same, async -> ValueError: Tool t returned a list with 0 messages bound to tool_call_id 'call-1';
B: list-form Command alone (list input) -> OK
B: list-form Command wrapped in list[Command] -> ValueError: Tool t returned a list with 0 messages bound to tool_call_id 'call-1';
Full traceback (default handle_tool_errors, libs/prebuilt/langgraph/prebuilt/tool_node.py at HEAD 230927fb):
File ".../langgraph/prebuilt/tool_node.py", line 969, in _execute_tool_sync
return self._normalize_tool_response(
File ".../langgraph/prebuilt/tool_node.py", line 1446, in _normalize_tool_response
return self._validate_tool_command_list(response, tool_call, input_type)
File ".../langgraph/prebuilt/tool_node.py", line 1485, in _validate_tool_command_list
raise ValueError(msg)
ValueError: Tool t returned a list with 0 messages bound to tool_call_id 'call-1'; expected exactly one terminating ToolMessage.
With handle_tool_errors=True the exception does not reach the caller; the LLM instead receives ToolMessage(content='Error: ValueError("Tool t returned a list with 0 messages bound to tool_call_id \'call-1\'; expected exactly one terminating ToolMessage.")', status="error").
Description
A tool allowed to return list[Command | ToolMessage] is rejected with ValueError: ... returned a list with 0 messages bound to tool_call_id ...; expected exactly one terminating ToolMessage even though the list contains exactly one terminating ToolMessage for the tool call. It happens whenever that terminator is supplied in either of these valid forms:
- a normal dict message inside a dict-form
Command.update["messages"], e.g.Command(update={"messages": [{"type": "tool", "content": "done", "tool_call_id": id}]}); - a
ToolMessagein a list-formCommand.update, e.g.Command(update=[ToolMessage(...)])— the documented update shape when ToolNode is invoked with a message list.
The identical Command returned on its own (not wrapped in a list) is accepted, so two calls with the same tool result disagree. Sync and async hit the same helper (_execute_tool_sync / _execute_tool_async → _normalize_tool_response → _validate_tool_command_list), so both fail identically. With the default handle_tool_errors the error propagates and kills the tool node; with handle_tool_errors=True the model is fed a bogus error ToolMessage.
Actual output (verbatim, from two independent reproductions of the script above):
plain ToolMessage Command alone (dict input) -> OK
dict-message Command alone (dict input) -> OK
dict-message Command in list (dict input) -> ValueError: Tool t returned a list with 0 messages bound to tool_call_id 'call-1'; expected exactly one terminating ToolMessage.
dict-message Command in list, async -> ValueError: Tool t returned a list with 0 messages bound to tool_call_id 'call-1'; expected exactly one terminating ToolMessage.
list-form Command alone (list input) -> OK
list-form Command in list (list input) -> ValueError: Tool t returned a list with 0 messages bound to tool_call_id 'call-1'; expected exactly one terminating ToolMessage.
A second verifier reproduced the same divergence in an isolated worktree at commit 230927fb3a9a, including end-to-end through a StateGraph + ToolNode, and confirmed convert_to_messages([{"type": "tool", "content": "done", "tool_call_id": "call-1"}]) yields a ToolMessage with tool_call_id == "call-1".
Expected behaviour
All three terminator shapes should be accepted by the list-return validator, exactly as they already are by the single-Command path:
convert_to_messagesturns{"type": "tool", "content": "done", "tool_call_id": id}into aToolMessage, so it is a terminatingToolMessageby the framework's own definition.- A list-form
Command.updateof messages is valid for list input (the sibling path accepts it and_validate_tool_commandhandles it at line 1527-1540).
Basis:
_validate_tool_command_listdocstring (tool_node.py:1463-1465): "Requires exactly one terminating ToolMessage (matching the outer tool_call_id) across the list — either as a top-level element or nested in aCommand.update["messages"]." A dict message under that key satisfies it; the counter only recognizes pre-constructedToolMessageobjects.- The sibling branch gets it right:
_validate_tool_command(tool_node.py:1541-1542) runsmessages_update = convert_to_messages(messages_update)(comment: "convert to message objects if updates are in a dict format") before looking for the matchingToolMessage. - feat(prebuilt): allow ToolNode tools to return list[Command | ToolMessage] #7596 states the same "top-level or nested inside a
Command.update["messages"]" contract.
Root cause: libs/prebuilt/langgraph/prebuilt/tool_node.py:1474-1477 — the elif isinstance(item, Command) and isinstance(item.update, dict) branch iterates the raw item.update[self._messages_key] and counts isinstance(msg, ToolMessage) without normalizing, and there is no branch at all for a list-form Command.update. Counting therefore disagrees with _validate_tool_command, which normalizes with convert_to_messages.
Reachability: every tool result goes through _normalize_tool_response → _validate_tool_command_list (tool_node.py:1432-1448, called from _execute_tool_sync/_execute_tool_async). Any tool using the supported list[Command | ToolMessage] return shape to emit state updates plus its result — e.g. [Command(update={"messages": [{"type": "tool", ...}]}), Command(goto=...)], or a Send-dispatched tool call invoked with a message list returning [Command(update=[ToolMessage(...)])] — is rejected.
System Info
langgraph1.2.11 (libs/prebuilt/langgraph/prebuilt/tool_node.py, same code as HEAD230927fb3a9ac9b2893a30322b4dfea7cdea9a8f; both have the branch at line 1474)langgraph-prebuilt1.1.0,langchain-core1.6.3- Python 3.13.15
- macOS 26.6.2 (Darwin 25.6.0, arm64)
Happy to be assigned this issue; I can open a PR that normalizes each Command.update (dict and list form) with convert_to_messages before counting, so the list validator agrees with _validate_tool_command, plus a regression test covering all three terminator shapes and the async path.
Activity
Bboyjie commentedon Sep 16, 2026
Hi maintainers, I'd like to work on this issue if it is still available.
Proposed scope: update
_validate_tool_command_listto normalize both dict-form and list-formCommand.updatewithconvert_to_messages()before counting matchingToolMessageterminators, and add sync/async regression tests for the three supported shapes. I will keep the change limited tolibs/prebuilt/langgraph/prebuilt/tool_node.pyandlibs/prebuilt/tests/test_tool_node.py, then runmake format,make lint, and the focused test target.Could you confirm the approach and assign #8924 to me before I prepare the PR?
MohammadHijjawi97 commentedon Sep 16, 2026
I'd like to take this.
Reproduced: a list[Command] with a dict-message terminator or a list-form Command.update is rejected even though the same Command alone is accepted. Fix is in #8946 : normalize with convert_to_messages before counting. Sync and async tests included.
Please assign this to Mohammad Hijjawi (@MohammadHijjawi97) so the PR can stay open.
leilei3167 commentedon Sep 18, 2026
Hi — I'd like to work on this if it's still available.
Proposed fix: update
_validate_tool_command_listso dict-form and list-formCommand.updateare normalized withconvert_to_messages()before counting matchingToolMessageterminators (same contract as_validate_tool_command/ #7596). Scope stays inlibs/prebuilt/langgraph/prebuilt/tool_node.pyplus sync/async regression tests for the three terminator shapes.Could a maintainer please assign this to me so I can open a PR? Thanks!