ScrapeGraphAI/Scrapegraph-ai · error · ValueError

Adjacent state keys found without an operator between them.

Error message

Adjacent state keys found without an operator between them.

What it means

ValueError from parse_expression: two state keys appear next to each other with whitespace but no operator between them (regex matches 'key1 key2'). Keys must be joined explicitly with & or |.

Source

Thrown at scrapegraphai/utils/parse_state_keys.py:47

    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 expression
        or "&|" in expression
        or "|&" in expression
    ):
        raise ValueError("Invalid operator usage.")

    open_parentheses = close_parentheses = 0
    for i, char in enumerate(expression):
        if char == "(":
            open_parentheses += 1
        elif char == ")":

View on GitHub (pinned to 532dfffbf6)

Solutions

  1. Insert explicit operators: 'fetch_node & parse_node'
  2. Validate the expression string before passing it (e.g. unit-test edge conditions)

Example fix

# before
expr = 'fetch_node parse_node'
# after
expr = 'fetch_node & parse_node'
Defensive patterns

Strategy: validation

Validate before calling

import re
keys = list(state)
if re.search(r"\b(" + "|".join(map(re.escape, keys)) + r")\s+(" + "|".join(map(re.escape, keys)) + r")\b", expression):
    raise ValueError("adjacent keys")  # or auto-insert '&'

Try / catch

try:
    keys = parse_expression(expr, state)
except ValueError as e:
    expr2 = re.sub(r"(?<=[a-z_])\s+(?=[a-z_])", " & ", expr2)
    keys = parse_expression(expr2, state)

Prevention

When it happens

Trigger: Calling parse_expression('fetch_node parse_node', state) — implicit 'and' via a space is not supported.

Common situations: Writing expressions in a Python-like style ('a b' meaning and) or a typo deleting the & between keys.

Related errors


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