ScrapeGraphAI/Scrapegraph-ai · error · ValueError
Error evaluating condition '{condition}' in {self.node_name}
Error message
Error evaluating condition '{condition}' in {self.node_name}: {e} What it means
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.
Source
Thrown at scrapegraphai/nodes/conditional_node.py:110
condition (str): The condition expression to evaluate.
Returns:
bool: The result of the condition evaluation.
"""
# Combine state and allowed functions for evaluation context
eval_globals = self.eval_instance.functions.copy()
eval_globals.update(state)
try:
result = simple_eval(
condition,
names=eval_globals,
functions=self.eval_instance.functions,
operators=self.eval_instance.operators,
)
return bool(result)
except Exception as e:
raise ValueError(
f"Error evaluating condition '{condition}' in {self.node_name}: {e}"
)
View on GitHub (pinned to 532dfffbf6)
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
Example fix
# before condition = "len(parsed_docs) > 0" # after condition = "parsed_docs is not None and len(parsed_docs) > 0"
Defensive patterns
Strategy: try-catch
Validate before calling
# dry-run the condition against a sample state before deploying from asteval import Interpreter interp = Interpreter() interp.symtable.update(sample_state) assert interp(condition_expr) is not None or True # smoke test
Try / catch
try:
nxt = node.execute(state)
except ValueError as e:
if 'Error evaluating condition' in str(e):
logger.warning('condition failed; defaulting to false branch')
nxt = node.false_node_name
else:
raise Prevention
- Null-guard state keys inside condition expressions
- Keep conditions to simple comparisons asteval supports
- Test conditions with realistic state dicts
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- You need to provide key_name inside the node config
- ConditionalNode's next nodes are not set properly.
- 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/b03c80729cdb6863.
Report an issue: GitHub.