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

Raised by BaseNode._parse_input_keys when the boolean expression used to declare a node's input contains two state key names directly adjacent to each other with no '&' or '|' operator between them. ScrapeGraphAI parses these expressions to compute which state keys a node consumes, so a malformed expression cannot be evaluated. The check is done with a regex that finds word-boundary-separated key names next to each other.

Source

Thrown at scrapegraphai/nodes/base_node.py:164

        Returns:
            List[str]: A list of key names that match the input keys expression logic.

        Raises:
            ValueError: If the expression is invalid or if no state keys match the expression.
        """

        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 == "(":

View on GitHub (pinned to 532dfffbf6)

Solutions

  1. Join all keys with explicit operators, e.g. input="key1 & key2" or "key1 | key2"
  2. If you intended both keys to be required, use '&' between every pair
  3. Check for accidental concatenation of key names without separators in the input string
  4. Verify the state keys you reference actually exist in the graph's state schema

Example fix

// before
node = MyNode(node_config={"input": "parsed_docs user_prompt"})
// after
node = MyNode(node_config={"input": "parsed_docs & user_prompt"})
Defensive patterns

Strategy: validation

Validate before calling

import re
def valid_input_expression(expr: str, state_keys) -> bool:
    keys = [re.escape(k) for k in state_keys]
    pat = r'(?:' + '|'.join(keys) + r')\b\s*\b(?:' + '|'.join(keys) + r')\b'
    return not re.search(pat, expr)

Try / catch

try:
    node.get_input_keys(state)
except ValueError as e:
    if 'Adjacent state keys' in str(e):
        # fix expression: join keys with '&'
        fixed = ' & '.join(expr.split())
    else:
        raise

Prevention

When it happens

Trigger: Passing node_config input like "key1 key2" or "parsed_docs user_prompt" (space-separated keys) instead of "key1 & key2". Also happens after spaces are stripped if two key names appear back-to-back, e.g. a key whose name ends with another key's name boundary-adjacent in the expression.

Common situations: Writing custom nodes and copying an input string that omits operators; renaming state keys so two adjacent tokens both match state key names; using commas instead of '|' between keys.

Related errors


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