{"record":{"id":"db63df2a4d75e220","repo":"ScrapeGraphAI/Scrapegraph-ai","slug":"conditionalnode-s-next-nodes-are-not-set-properly","errorCode":null,"errorMessage":"ConditionalNode's next nodes are not set properly.","messagePattern":"ConditionalNode's next nodes are not set properly\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"scrapegraphai/nodes/conditional_node.py","lineNumber":73,"sourceCode":"        self.true_node_name = None\n        self.false_node_name = None\n        self.condition = self.node_config.get(\"condition\", None)\n        self.eval_instance = EvalWithCompoundTypes()\n        self.eval_instance.functions = {\"len\": len}\n\n    def execute(self, state: dict) -> dict:\n        \"\"\"\n        Checks if the specified key is present in the state and decides the next node accordingly.\n\n        Args:\n            state (dict): The current state of the graph.\n\n        Returns:\n            str: The name of the next node to execute based on the presence of the key.\n        \"\"\"\n\n        if self.true_node_name is None:\n            raise ValueError(\"ConditionalNode's next nodes are not set properly.\")\n\n        if self.condition:\n            condition_result = self._evaluate_condition(state, self.condition)\n        else:\n            value = state.get(self.key_name)\n            condition_result = value is not None and value != \"\"\n\n        if condition_result:\n            return self.true_node_name\n        else:\n            return self.false_node_name\n\n    def _evaluate_condition(self, state: dict, condition: str) -> bool:\n        \"\"\"\n        Parses and evaluates the condition expression against the state.\n\n        Args:\n            state (dict): The current state of the graph.","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/ScrapeGraphAI/Scrapegraph-ai/blob/532dfffbf6ee823a6c9cf8cfedc24a93bf026780/scrapegraphai/nodes/conditional_node.py#L55-L91","documentation":"ConditionalNode.execute requires true_node_name to be set before it can choose the next node; this is normally wired by the graph builder. If the node was never connected to successors via set_conditional_next_nodes (or equivalent), true_node_name stays None and this ValueError fires.","triggerScenarios":"Calling execute() on a standalone ConditionalNode that was never added to a graph; building a custom graph and forgetting to register the conditional edges; adding the node to the graph without connecting its 'true' branch.","commonSituations":"Unit-testing ConditionalNode.execute directly; constructing a custom ScriptedGraph/AbstractGraph and skipping edge registration; refactoring graph wiring and dropping the conditional edge.","solutions":["Let the graph builder wire the node instead of calling execute() manually","Ensure the conditional node is connected in the graph so true_node_name/false_node_name get set","If testing standalone, set node.true_node_name and node.false_node_name before calling execute"],"exampleFix":"# before\nnode = ConditionalNode('branch', ...)  # never added to graph edges\nresult = node.execute(state)\n# after\nnode.true_node_name = 'GenerateAnswer'\nnode.false_node_name = 'SearchFallback'\nresult = node.execute(state)","handlingStrategy":"validation","validationCode":"assert node.true_node_name is not None, 'wire conditional edges via the graph builder before execute'","typeGuard":null,"tryCatchPattern":"try:\n    nxt = node.execute(state)\nexcept ValueError as e:\n    if 'next nodes are not set' in str(e):\n        raise RuntimeError('graph wiring incomplete: connect conditional branches')\n    raise","preventionTips":["Never call ConditionalNode.execute outside a built graph","Review graph edge registration whenever adding conditional nodes"],"tags":["scrapegraphai","conditional-node","graph-wiring"],"backgroundTag":"incomplete-graph-wiring","analyzedSha":"532dfffbf6ee823a6c9cf8cfedc24a93bf026780","analyzedAt":"2026-08-28T15:19:38.821Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}