ScrapeGraphAI/Scrapegraph-ai · error · ValueError
No state keys matched the expression.
Error message
No state keys matched the expression.
Expression was {expression}.
State contains keys: {", ".join(state.keys())} What it means
The expression parsed successfully but evaluated to an empty result — none of the tokens in the expression match keys present in the graph state at evaluation time. The message (bug: uses literal braces, so it is not f-string interpolated) is meant to show the expression and available keys.
Source
Thrown at scrapegraphai/nodes/base_node.py:224
def evaluate_expression(expression: str) -> List[str]:
"""Evaluate an expression with parentheses."""
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)
result = evaluate_expression(expression)
if not result:
raise ValueError(
f"""No state keys matched the expression.
Expression was {expression}.
State contains keys: {", ".join(state.keys())}"""
)
final_result = []
for key in result:
if key not in final_result:
final_result.append(key)
return final_result
View on GitHub (pinned to 532dfffbf6)
Solutions
- Print/list the graph state keys and correct the expression to reference existing ones
- Check the node's expected state keys against the graph definition (e.g. SmartScraperGraph state)
- Update custom nodes after upgrading the library if state keys were renamed
- When unit-testing nodes, pass a state dict populated with all expected keys
Example fix
# before input="my_docs & query" # after (match actual state keys) input="parsed_docs & user_prompt"
Defensive patterns
Strategy: validation
Validate before calling
def keys_exist(expr: str, state: dict) -> bool:
import re
tokens = set(re.split(r'[&|()\s]+', expr)) - {'', '&', '|'}
return all(t in state for t in tokens) Try / catch
try:
result = node.get_input_keys(state)
except ValueError as e:
log state keys and expression, then correct the expression Prevention
- Keep custom-node input keys in sync with the graph state schema
- After library upgrades, re-check state key names used in node configs
When it happens
Trigger: Referencing a key that doesn't exist in state, e.g. input="my_docs" when state only has 'parsed_docs'; graph state schema changed after the node was written; typo in a key name.
Common situations: Upgrading ScrapeGraphAI where state key names changed; custom nodes referencing renamed state attributes; running a node standalone with a partial state dict during tests.
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.
- You need to provide key_name inside the node config
AI-assisted analysis of ScrapeGraphAI/Scrapegraph-ai@532dfffbf6 (2026-08-28).
Data as JSON: /api/errors/90f81efef7d79f93.
Report an issue: GitHub.