ScrapeGraphAI/Scrapegraph-ai · error · ValueError

Conditional Node returned a node name '{result}' that does n

Error message

Conditional Node returned a node name '{result}' that does not exist in the graph

What it means

During execution, a conditional node's execute() returned a string naming the next node, but that string is not any node's node_name in the graph. _get_next_node therefore cannot route and raises before continuing execution.

Source

Thrown at scrapegraphai/graphs/base_graph.py:230

                    "total_tokens": cb.total_tokens,
                    "prompt_tokens": cb.prompt_tokens,
                    "completion_tokens": cb.completion_tokens,
                    "successful_requests": cb.successful_requests,
                    "total_cost_USD": cb.total_cost,
                    "exec_time": node_exec_time,
                }

        return result, node_exec_time, cb_data

    def _get_next_node(self, current_node, result):
        """Determines the next node to execute based on current node type and result."""
        if current_node.node_type == "conditional_node":
            node_names = {node.node_name for node in self.nodes}
            if result in node_names:
                return result
            elif result is None:
                return None
            raise ValueError(
                f"Conditional Node returned a node name '{result}' that does not exist in the graph"
            )

        return self.edges.get(current_node.node_name)

    def _execute_standard(self, initial_state: dict) -> Tuple[dict, list]:
        """
        Executes the graph by traversing nodes
        starting from the entry point using the standard method.
        """
        current_node_name = self.entry_point
        state = initial_state

        total_exec_time = 0.0
        exec_info = []
        cb_total = {
            "total_tokens": 0,
            "prompt_tokens": 0,

View on GitHub (pinned to 532dfffbf6)

Solutions

  1. Make the conditional node return exactly one of the graph's registered node_name strings (or None to stop).
  2. If routing is LLM-driven, constrain the output (enum/choices in the prompt) and validate the returned name against the node set before returning it.
  3. Log the set of valid names next to the returned value to spot mismatches fast.

Example fix

# before
class Router(ConditionalNode):
    def execute(self, state):
        return 'parse'  # graph node is named 'ParseNode'

# after
class Router(ConditionalNode):
    def execute(self, state):
        return 'ParseNode'
Defensive patterns

Strategy: validation

Validate before calling

valid_names = {n.node_name for n in graph.nodes}
result = router_node.execute(state)
assert result is None or result in valid_names, f'router returned unknown node {result!r}'

Type guard

def is_valid_route(result, graph) -> bool:
    names = {n.node_name for n in graph.nodes}
    return result is None or result in names

Try / catch

try:
    final_state, info = graph.execute(inputs)
except ValueError as e:
    if 'does not exist in the graph' in str(e):
        logger.error('Router returned unknown node; check node names vs routing table')
    raise

Prevention

When it happens

Trigger: A custom conditional node whose execute returns e.g. 'parse' when the graph contains 'ParseNode'; dynamic LLM-driven routing where the model outputs a node name not in the graph; returning a node object or a truthy non-None value that is not a registered name.

Common situations: Renaming nodes but not the strings returned by conditional logic; LLM-based routers returning free-form text instead of one of the allowed names; typos between the routing table and node_name declarations.

Related errors


AI-assisted analysis of ScrapeGraphAI/Scrapegraph-ai@532dfffbf6 (2026-08-28). Data as JSON: /api/errors/700ab3574350b17f. Report an issue: GitHub.