ScrapeGraphAI/Scrapegraph-ai · error · ValueError
Invalid operator usage.
Error message
Invalid operator usage.
What it means
Raised when the input-key boolean expression starts or ends with '&' or '|', or contains doubled ('&&', '||') or mixed ('&|', '|&') operator sequences. These shapes make the expression unparseable, so the node refuses to compute its input keys.
Source
Thrown at scrapegraphai/nodes/base_node.py:178
+ "|".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 == ")":
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."""View on GitHub (pinned to 532dfffbf6)
Solutions
- Use single '&' and '|' operators only: "key1 & key2 | key3"
- Strip trailing/leading operators from programmatically built expressions before passing them
- Never use '&&' or '||' in the input expression
Example fix
// before input="parsed_docs && user_prompt" // after input="parsed_docs & user_prompt"
Defensive patterns
Strategy: validation
Validate before calling
def valid_ops(expr: str) -> bool:
e = expr.replace(' ', '')
return not (e.startswith(('&','|')) or e.endswith(('&','|')) or '&&' in e or '||' in e or '&|' in e or '|&' in e) Try / catch
try:
node.get_input_keys(state)
except ValueError as e:
raise ValueError(f'Bad input expression, check operators: {e}') from e Prevention
- Use single-char operators '&'/'|' only
- Never build expressions by blind string concatenation; validate before passing
When it happens
Trigger: input="& key1", input="key1 |", input="key1 && key2", or input="key1 |& key2". Any leading/trailing operator or doubled operator token triggers this immediately after whitespace is stripped.
Common situations: Typos when hand-writing input expressions; dynamically building the expression string and accidentally appending a trailing '|'; assuming '&&'/'||' (Python/JS style) work instead of ScrapeGraphAI's single '&' and '|'.
Related errors
- Adjacent state keys found without an operator between them.
- Invalid operator placement: operators cannot be adjacent.
- Missing or unbalanced parentheses in expression.
- No state keys matched the 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/e7985d7f0c28f5e0.
Report an issue: GitHub.