ScrapeGraphAI/Scrapegraph-ai · error · ValueError
Node with name '{node.node_name}' already exists in the grap
Error message
Node with name '{node.node_name}' already exists in the graph.
You can change it by setting the 'node_name' attribute. What it means
BaseGraph.append_node refuses to add a node whose node_name already exists among the graph's nodes, because routing (edges dict keyed by node_name) and conditional-node resolution rely on unique names. The message suggests overriding the node_name attribute.
Source
Thrown at scrapegraphai/graphs/base_graph.py:388
logger.info(state["generated_code"])
elif "merged_script" in state:
logger.info(state["merged_script"])
logger.info("✨ Try enhanced version of ScrapegraphAI at %s ✨", CLICKABLE_URL)
return state, exec_info
def append_node(self, node):
"""
Adds a node to the graph.
Args:
node (BaseNode): The node instance to add to the graph.
"""
# if node name already exists in the graph, raise an exception
if node.node_name in {n.node_name for n in self.nodes}:
raise ValueError(
f"""Node with name '{node.node_name}' already exists in the graph.
You can change it by setting the 'node_name' attribute."""
)
last_node = self.nodes[-1]
self.raw_edges.append((last_node, node))
self.nodes.append(node)
self.edges = self._create_edges(set(self.raw_edges))
View on GitHub (pinned to 532dfffbf6)
Solutions
- Give the new node a unique name via its constructor: FetchNode(node_name='fetch_retry', ...).
- Skip the append if the name already exists (check {n.node_name for n in graph.nodes} first) when the node is intentionally identical.
- Reuse the existing node instance instead of appending a duplicate.
Example fix
# before graph.append_node(FetchNode(node_config=cfg)) graph.append_node(FetchNode(node_config=cfg)) # duplicate default name 'fetch' # after graph.append_node(FetchNode(node_config=cfg)) graph.append_node(FetchNode(node_name='fetch_second', node_config=cfg))
Defensive patterns
Strategy: validation
Validate before calling
existing = {n.node_name for n in graph.nodes}
if node.node_name in existing:
node.node_name = f'{node.node_name}_{len(existing)}' # or skip
graph.append_node(node) Type guard
def name_is_unique(node, graph) -> bool:
return node.node_name not in {n.node_name for n in graph.nodes} Try / catch
try:
graph.append_node(node)
except ValueError as e:
if 'already exists' in str(e):
node.node_name += '_2'
graph.append_node(node)
else:
raise Prevention
- Pass explicit node_name when appending same-class nodes.
- Check the node-name set before appending in loops.
- Prefer reusing existing instances over appending duplicates.
When it happens
Trigger: Calling graph.append_node(FetchNode(...)) twice, or appending two nodes of the same class with default names (both default to e.g. 'fetch'); appending a node whose node_name was manually set to an existing one.
Common situations: Building custom pipelines in a loop that instantiates the same node class repeatedly; copy-pasting node blocks without changing node_name; appending a second FetchNode for retry logic.
Related errors
- ConditionalNode '{node.node_name}' must have exactly two out
- Failed to set false_node_name for ConditionalNode '{node.nod
- Conditional Node returned a node name '{result}' that does n
AI-assisted analysis of ScrapeGraphAI/Scrapegraph-ai@532dfffbf6 (2026-08-28).
Data as JSON: /api/errors/bfd02d8af6cf514b.
Report an issue: GitHub.