ScrapeGraphAI/Scrapegraph-ai · error · ValueError
Empty expression.
Error message
Empty expression.
What it means
ValueError from parse_expression: the boolean expression over state keys is empty (empty string or None). The function builds a regex from state keys, so at least one key/operator is required.
Source
Thrown at scrapegraphai/utils/parse_state_keys.py:37
Returns:
list: A list of state keys that match the boolean expression,
ensuring each key appears only once.
Example:
>>> parse_expression("user_input & (relevant_chunks | parsed_document | document)",
{"user_input": None, "document": None,
"parsed_document": None, "relevant_chunks": None})
['user_input', 'relevant_chunks', 'parsed_document', 'document']
This function evaluates the expression to determine the
logical inclusion of state keys based on provided boolean logic.
It checks for syntax errors such as unbalanced parentheses,
incorrect adjacency of operators, and empty expressions.
"""
if not expression:
raise ValueError("Empty expression.")
pattern = (
r"\b("
+ "|".join(re.escape(key) for key in state.keys())
+ r")(\b\s*\b)("
+ "|".join(re.escape(key) for key in state.keys())
+ r")\b"
)
if re.search(pattern, expression):
raise ValueError("Adjacent state keys found without an operator between them.")
expression = expression.replace(" ", "")
if (
expression[0] in "&|"
or expression[-1] in "&|"
or "&&" in expression
or "||" in expressionView on GitHub (pinned to 532dfffbf6)
Solutions
- Provide a non-empty expression of state keys joined by & (and) / | (or), e.g. 'key1 & key2'
- Skip the conditional edge when the expression is empty rather than calling parse_expression
Example fix
# before
keys = parse_expression(cond_expr or '', state)
# after
if not cond_expr:
return []
keys = parse_expression(cond_expr, state) Defensive patterns
Strategy: validation
Validate before calling
if not expression or not expression.strip():
return [] # skip edge
keys = parse_expression(expression, state) Type guard
def is_non_empty_expression(expr) -> bool:
return isinstance(expr, str) and len(expr.strip()) > 0 Try / catch
try:
keys = parse_expression(expr, state)
except ValueError as e:
logger.warning("bad edge expression %r: %s", expr, e)
keys = [] Prevention
- Default condition expressions to a real key, never ''
- Treat blank expressions as 'no edge' in config loaders
- Unit-test all conditional edge expressions
When it happens
Trigger: Calling parse_expression('', state) or parse_expression(None, state) — e.g. an edge condition expression left blank in graph config.
Common situations: Optional conditional edges where the condition string comes from config and defaults to empty; template variables for the expression not filled in.
Related errors
- Adjacent state keys found without an operator between them.
- Invalid operator usage.
- Invalid operator placement: operators cannot be adjacent.
- Missing or unbalanced parentheses in expression.
- No state keys matched the expression.
AI-assisted analysis of ScrapeGraphAI/Scrapegraph-ai@532dfffbf6 (2026-08-28).
Data as JSON: /api/errors/7f481df0743ced25.
Report an issue: GitHub.