ScrapeGraphAI/Scrapegraph-ai · error · ValueError

No state keys matched the expression.

Error message

No state keys matched the expression.

What it means

ValueError from parse_expression: the expression parsed successfully but evaluated to no state keys — every key referenced in the expression is absent from (or not truthy in) the provided state dict.

Source

Thrown at scrapegraphai/utils/parse_state_keys.py:96

            if all(elem.strip() in state for elem in and_segment):
                return [elem.strip() for elem in and_segment if elem.strip() in state]
        return []

    def evaluate_expression(expression):
        while "(" in expression:
            start = expression.rfind("(")
            end = expression.find(")", start)
            sub_exp = expression[start + 1 : end]
            sub_result = evaluate_simple_expression(sub_exp)
            expression = (
                expression[:start] + "|".join(sub_result) + expression[end + 1 :]
            )
        return evaluate_simple_expression(expression)

    temp_result = evaluate_expression(expression)

    if not temp_result:
        raise ValueError("No state keys matched the expression.")

    final_result = []
    for key in temp_result:
        if key not in final_result:
            final_result.append(key)

    return final_result

View on GitHub (pinned to 532dfffbf6)

Solutions

  1. Verify every key in the expression exists in the state dict
  2. Update the expression after renaming nodes or state keys
  3. Run with a state dict containing the referenced keys before evaluating edges

Example fix

# before
keys = parse_expression('fetch_node', state)  # state has 'fetch_html'
# after
keys = parse_expression('fetch_html', state)
Defensive patterns

Strategy: validation

Validate before calling

import re
tokens = set(re.findall(r"[A-Za-z_][A-Za-z0-9_]*", expression))
missing = {t for t in tokens if t not in state}
assert not missing, f"keys not in state: {missing}"

Type guard

def expression_keys_in_state(expr, state) -> bool:
    import re
    return all(t in state for t in re.findall(r"[A-Za-z_][A-Za-z0-9_]*", expr))

Try / catch

try:
    keys = parse_expression(expr, state)
except ValueError as e:
    if "No state keys" in str(e):
        keys = list(state)  # or skip edge
    else:
        raise

Prevention

When it happens

Trigger: parse_expression(' nonexistent_key ', {'a': 1}) — the expression references keys not present in state.

Common situations: Renaming a node/state key but not updating edge conditions; running a subgraph whose state lacks keys used by the inherited condition.

Related errors


AI-assisted analysis of ScrapeGraphAI/Scrapegraph-ai@532dfffbf6 (2026-08-28). Data as JSON: /api/errors/625f59b75d41db4d. Report an issue: GitHub.