ScrapeGraphAI/Scrapegraph-ai · error · ValueError

Empty expression.

Error message

Empty expression.

What it means

The lowest-level check in _parse_input_keys: the node's input expression is empty/None, so there is nothing to match against state keys and a ValueError('Empty expression.') is thrown. It surfaces wrapped by get_input_keys as 'Error parsing input keys for {node_name}'.

Source

Thrown at scrapegraphai/nodes/base_node.py:154

    def _parse_input_keys(self, state: dict, expression: str) -> List[str]:
        """
        Parses the input keys expression to extract
        relevant keys from the state based on logical conditions.
        The expression can contain AND (&), OR (|), and parentheses to group conditions.

        Args:
            state (dict): The current state of the graph.
            expression (str): The input keys expression to parse.

        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 "&|"

View on GitHub (pinned to 532dfffbf6)

Solutions

  1. Set a non-empty input expression on the node, e.g. input='doc' or input='user_prompt| doc'.
  2. If the input is built from config, default it: node_input = cfg.get('input') or 'doc'.
  3. Add a constructor-level assertion/guard so misconfiguration fails fast with a clearer message.

Example fix

# before
my_node = MyNode(input='', node_config=cfg)

# after
my_node = MyNode(input='doc', node_config=cfg)
Defensive patterns

Strategy: validation

Validate before calling

assert node.input, f'{type(node).__name__} needs a non-empty input expression like "doc" or "user_prompt| doc"'

Type guard

def has_input_expression(node) -> bool:
    return bool(getattr(node, 'input', None))

Try / catch

try:
    final_state, info = graph.execute(inputs)
except ValueError as e:
    if 'Empty expression' in str(e.__cause__ or ''):
        node.input = 'doc'
        final_state, info = graph.execute(inputs)
    else:
        raise

Prevention

When it happens

Trigger: Constructing a node with input='' or input=None (e.g. a custom node whose input config was not populated, or f-string config producing an empty string) and then executing it.

Common situations: Custom nodes where the input attribute is built from a config value that is missing; dynamically generated node definitions with a blank input field; refactoring that drops the input argument.

Related errors


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