ValueError
langgraph.exceptions.ValueError
Stack trace
ValueError: ToolNode tool 'my_tool' not found in tools list
File "/usr/local/lib/python3.9/site-packages/langgraph/execution.py", line 123, in execute
raise ValueError(f"ToolNode tool '{tool_name}' not found in tools list") Why it happens
This error occurs because the ToolNode in your LangGraph graph references a tool name that is missing from the tools list passed to the graph executor. The executor requires all tools used by ToolNodes to be registered and available in the tools list to run the graph.
Detection
Before execution, verify that every ToolNode's tool name exists in the tools list dictionary keys. Add validation to log missing tools before runtime errors occur.
Causes & fixes
The tool name specified in the ToolNode does not match any key in the tools list dictionary.
Ensure the tool name string in the ToolNode exactly matches a key in the tools list dictionary, including case sensitivity.
The tools list passed to the graph executor is incomplete or missing the required tool.
Add the missing tool instance to the tools list dictionary before passing it to the graph executor.
Typo or mismatch in the tool name between graph definition and tools list keys.
Double-check and correct any spelling or casing mismatches between the ToolNode's tool name and the tools list keys.
Code: broken vs fixed
from langgraph import Graph, ToolNode
# Define a ToolNode referencing 'my_tool'
node = ToolNode(tool='my_tool')
graph = Graph(nodes=[node])
# Missing 'my_tool' in tools list causes error
result = graph.execute(tools={}) # This line raises ValueError import os
from langgraph import Graph, ToolNode, Tool
# Set API key or environment variables as needed
os.environ['API_KEY'] = os.environ.get('API_KEY', '')
# Define the tool instance with the correct name
my_tool_instance = Tool(name='my_tool')
# Define a ToolNode referencing 'my_tool'
node = ToolNode(tool='my_tool')
graph = Graph(nodes=[node])
# Pass tools list with the required tool instance
result = graph.execute(tools={'my_tool': my_tool_instance}) # Fixed: tool included
print(result) Workaround
Wrap the graph execution call in try/except ValueError, catch the missing tool error, then dynamically add the missing tool to the tools list and retry execution.
Prevention
Implement validation before graph execution to confirm all ToolNode tool names exist in the tools list dictionary, preventing runtime errors from missing tools.