{"record":{"id":"b03c80729cdb6863","repo":"ScrapeGraphAI/Scrapegraph-ai","slug":"error-evaluating-condition-condition-in-self","errorCode":null,"errorMessage":"Error evaluating condition '{condition}' in {self.node_name}: {e}","messagePattern":"Error evaluating condition '(.+?)' in (.+?): (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"scrapegraphai/nodes/conditional_node.py","lineNumber":110,"sourceCode":"            condition (str): The condition expression to evaluate.\n\n        Returns:\n            bool: The result of the condition evaluation.\n        \"\"\"\n        # Combine state and allowed functions for evaluation context\n        eval_globals = self.eval_instance.functions.copy()\n        eval_globals.update(state)\n\n        try:\n            result = simple_eval(\n                condition,\n                names=eval_globals,\n                functions=self.eval_instance.functions,\n                operators=self.eval_instance.operators,\n            )\n            return bool(result)\n        except Exception as e:\n            raise ValueError(\n                f\"Error evaluating condition '{condition}' in {self.node_name}: {e}\"\n            )\n","sourceCodeStart":92,"sourceCodeEnd":113,"githubUrl":"https://github.com/ScrapeGraphAI/Scrapegraph-ai/blob/532dfffbf6ee823a6c9cf8cfedc24a93bf026780/scrapegraphai/nodes/conditional_node.py#L92-L113","documentation":"ConditionalNode._evaluate_condition uses asteval to safely evaluate the configured condition expression against the state; any exception during evaluation (unknown state variable, type error, unsupported operator, bad syntax) is wrapped in this ValueError that includes the node name and original error.","triggerScenarios":"A condition referencing a state key that is absent (NameError in eval), comparing incompatible types (e.g. 'len(parsed_docs) > \"3\"'), or using Python features asteval does not support (comprehensions, attribute access restrictions).","commonSituations":"Writing conditions against state keys that may be None on some paths; conditions that assume a type (list/int) the state doesn't hold for a given run; asteval's restricted eval rejecting a valid-Python expression.","solutions":["Read the embedded '{e}' message to identify the underlying eval failure","Guard the condition against missing/None values, e.g. \"parsed_docs is not None and len(parsed_docs) > 0\"","Keep conditions to simple comparisons/logic supported by asteval (no imports, comprehensions, or complex attribute chains)","Test the condition string with the actual state dict in isolation"],"exampleFix":"# before\ncondition = \"len(parsed_docs) > 0\"\n# after\ncondition = \"parsed_docs is not None and len(parsed_docs) > 0\"","handlingStrategy":"try-catch","validationCode":"# dry-run the condition against a sample state before deploying\nfrom asteval import Interpreter\ninterp = Interpreter()\ninterp.symtable.update(sample_state)\nassert interp(condition_expr) is not None or True  # smoke test","typeGuard":null,"tryCatchPattern":"try:\n    nxt = node.execute(state)\nexcept ValueError as e:\n    if 'Error evaluating condition' in str(e):\n        logger.warning('condition failed; defaulting to false branch')\n        nxt = node.false_node_name\n    else:\n        raise","preventionTips":["Null-guard state keys inside condition expressions","Keep conditions to simple comparisons asteval supports","Test conditions with realistic state dicts"],"tags":["scrapegraphai","conditional-node","condition-evaluation","asteval"],"backgroundTag":"expression-evaluation-failed","analyzedSha":"532dfffbf6ee823a6c9cf8cfedc24a93bf026780","analyzedAt":"2026-08-28T15:19:38.821Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}