NodeNotFound
langgraph.exceptions.NodeNotFound
Stack trace
Traceback (most recent call last):
File "app.py", line 42, in <module>
result = graph.execute(node_name="start")
File "/usr/local/lib/python3.10/site-packages/langgraph/graph.py", line 88, in execute
node = self.nodes[node_name]
KeyError: 'start'
langgraph.exceptions.NodeNotFound: Node 'start' not found in graph nodes. Why it happens
LangGraph requires all nodes referenced in execution or edges to be defined in the graph's node dictionary. If a node name is misspelled, missing, or not added before execution, the graph cannot resolve it and raises NodeNotFound. This ensures graph integrity and prevents runtime failures.
Detection
Before executing the graph, validate that all node names used in edges and execution calls exist in the graph's node dictionary. Logging missing keys or using graph validation methods can catch this early.
Causes & fixes
The node name passed to graph.execute() does not exist in the graph nodes dictionary.
Ensure the node name argument matches exactly a node key added to the graph before execution.
A node referenced in an edge or dependency is not defined in the graph nodes.
Add all nodes referenced by edges or dependencies to the graph nodes dictionary before building or executing the graph.
Typo or case mismatch in node names between definition and usage.
Verify node names are consistent in spelling and case throughout the graph definition and execution calls.
Code: broken vs fixed
from langgraph import Graph
graph = Graph()
# Missing node 'start' definition
result = graph.execute(node_name="start") # This line raises NodeNotFound error import os
from langgraph import Graph
# Define and add node 'start' before execution
graph = Graph()
graph.add_node("start", lambda: "Hello World")
result = graph.execute(node_name="start") # Fixed: node defined
print(result) Workaround
Wrap the execute call in try/except NodeNotFound, log the missing node name, and add a default node dynamically or abort gracefully.
Prevention
Implement graph validation routines that check all referenced nodes exist before execution and enforce consistent naming conventions in graph construction.