{"record":{"id":"700ab3574350b17f","repo":"ScrapeGraphAI/Scrapegraph-ai","slug":"conditional-node-returned-a-node-name-result-t","errorCode":null,"errorMessage":"Conditional Node returned a node name '{result}' that does not exist in the graph","messagePattern":"Conditional Node returned a node name '(.+?)' that does not exist in the graph","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"scrapegraphai/graphs/base_graph.py","lineNumber":230,"sourceCode":"                    \"total_tokens\": cb.total_tokens,\n                    \"prompt_tokens\": cb.prompt_tokens,\n                    \"completion_tokens\": cb.completion_tokens,\n                    \"successful_requests\": cb.successful_requests,\n                    \"total_cost_USD\": cb.total_cost,\n                    \"exec_time\": node_exec_time,\n                }\n\n        return result, node_exec_time, cb_data\n\n    def _get_next_node(self, current_node, result):\n        \"\"\"Determines the next node to execute based on current node type and result.\"\"\"\n        if current_node.node_type == \"conditional_node\":\n            node_names = {node.node_name for node in self.nodes}\n            if result in node_names:\n                return result\n            elif result is None:\n                return None\n            raise ValueError(\n                f\"Conditional Node returned a node name '{result}' that does not exist in the graph\"\n            )\n\n        return self.edges.get(current_node.node_name)\n\n    def _execute_standard(self, initial_state: dict) -> Tuple[dict, list]:\n        \"\"\"\n        Executes the graph by traversing nodes\n        starting from the entry point using the standard method.\n        \"\"\"\n        current_node_name = self.entry_point\n        state = initial_state\n\n        total_exec_time = 0.0\n        exec_info = []\n        cb_total = {\n            \"total_tokens\": 0,\n            \"prompt_tokens\": 0,","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/ScrapeGraphAI/Scrapegraph-ai/blob/532dfffbf6ee823a6c9cf8cfedc24a93bf026780/scrapegraphai/graphs/base_graph.py#L212-L248","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Make the conditional node return exactly one of the graph's registered node_name strings (or None to stop).","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.","Log the set of valid names next to the returned value to spot mismatches fast."],"exampleFix":"# before\nclass Router(ConditionalNode):\n    def execute(self, state):\n        return 'parse'  # graph node is named 'ParseNode'\n\n# after\nclass Router(ConditionalNode):\n    def execute(self, state):\n        return 'ParseNode'","handlingStrategy":"validation","validationCode":"valid_names = {n.node_name for n in graph.nodes}\nresult = router_node.execute(state)\nassert result is None or result in valid_names, f'router returned unknown node {result!r}'","typeGuard":"def is_valid_route(result, graph) -> bool:\n    names = {n.node_name for n in graph.nodes}\n    return result is None or result in names","tryCatchPattern":"try:\n    final_state, info = graph.execute(inputs)\nexcept ValueError as e:\n    if 'does not exist in the graph' in str(e):\n        logger.error('Router returned unknown node; check node names vs routing table')\n    raise","preventionTips":["Define routing tables as constants derived from actual node_name values.","For LLM routers, validate/normalize the model output against the node set before returning.","Return None explicitly to end the branch instead of a sentinel string."],"tags":["conditional-node","routing","execution","node-name"],"backgroundTag":"invalid-node-routing-target","analyzedSha":"532dfffbf6ee823a6c9cf8cfedc24a93bf026780","analyzedAt":"2026-08-28T15:19:38.821Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}