ScrapeGraphAI/Scrapegraph-ai · error · ValueError

Invalid operator placement: operators cannot be adjacent.

Error message

Invalid operator placement: operators cannot be adjacent.

What it means

Character-scan safeguard that fires when two operator characters ('&' or '|') are directly adjacent anywhere in the expression, e.g. '&|' or '|&' in the middle of the string. Even though error 41 catches some doubled-operator cases, this loop guards sequences at any position.

Source

Thrown at scrapegraphai/nodes/base_node.py:188

        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 == ")":
                close_parentheses += 1
            # Check for invalid operator sequences
            if char in "&|" and i + 1 < len(expression) and expression[i + 1] in "&|":
                raise ValueError(
                    "Invalid operator placement: operators cannot be adjacent."
                )

        if open_parentheses != close_parentheses:
            raise ValueError("Missing or unbalanced parentheses in expression.")

        def evaluate_simple_expression(exp: str) -> List[str]:
            """Evaluate an expression without parentheses."""

            for or_segment in exp.split("|"):
                and_segment = or_segment.split("&")
                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: str) -> List[str]:

View on GitHub (pinned to 532dfffbf6)

Solutions

  1. Inspect the expression for adjacent operator characters and replace with a single operator
  2. When building from lists, filter out empty tokens before joining with operators
  3. Simplify the expression to well-formed '&'/'|' groups possibly with parentheses

Example fix

# before
parts = ['a', '', 'b']
expr = ' & '.join(parts)  # -> 'a &  & b'
# after
expr = ' & '.join(p for p in parts if p)
Defensive patterns

Strategy: validation

Validate before calling

def no_adjacent_ops(expr: str) -> bool:
    return all(not (c in '&|' and i+1 < len(expr) and expr[i+1] in '&|') for i, c in enumerate(expr))

Prevention

When it happens

Trigger: input="a |& b", input="a &| b", or any expression where an '&' immediately follows a '|' (or vice versa) at an arbitrary position.

Common situations: Editing an existing expression and leaving a stray operator; string concatenation bugs when composing input expressions from lists, e.g. ' & '.join(parts) where a part is empty.

Related errors


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