{"record":{"id":"e7985d7f0c28f5e0","repo":"ScrapeGraphAI/Scrapegraph-ai","slug":"invalid-operator-usage","errorCode":null,"errorMessage":"Invalid operator usage.","messagePattern":"Invalid operator usage\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"scrapegraphai/nodes/base_node.py","lineNumber":178,"sourceCode":"            + \"|\".join(re.escape(key) for key in state.keys())\n            + r\")\\b\"\n        )\n        if re.search(pattern, expression):\n            raise ValueError(\n                \"Adjacent state keys found without an operator between them.\"\n            )\n\n        expression = expression.replace(\" \", \"\")\n\n        if (\n            expression[0] in \"&|\"\n            or expression[-1] in \"&|\"\n            or \"&&\" in expression\n            or \"||\" in expression\n            or \"&|\" in expression\n            or \"|&\" in expression\n        ):\n            raise ValueError(\"Invalid operator usage.\")\n\n        open_parentheses = close_parentheses = 0\n        for i, char in enumerate(expression):\n            if char == \"(\":\n                open_parentheses += 1\n            elif char == \")\":\n                close_parentheses += 1\n            # Check for invalid operator sequences\n            if char in \"&|\" and i + 1 < len(expression) and expression[i + 1] in \"&|\":\n                raise ValueError(\n                    \"Invalid operator placement: operators cannot be adjacent.\"\n                )\n\n        if open_parentheses != close_parentheses:\n            raise ValueError(\"Missing or unbalanced parentheses in expression.\")\n\n        def evaluate_simple_expression(exp: str) -> List[str]:\n            \"\"\"Evaluate an expression without parentheses.\"\"\"","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/ScrapeGraphAI/Scrapegraph-ai/blob/532dfffbf6ee823a6c9cf8cfedc24a93bf026780/scrapegraphai/nodes/base_node.py#L160-L196","documentation":"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.","triggerScenarios":"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.","commonSituations":"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 '|'.","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"],"exampleFix":"// before\ninput=\"parsed_docs && user_prompt\"\n// after\ninput=\"parsed_docs & user_prompt\"","handlingStrategy":"validation","validationCode":"def valid_ops(expr: str) -> bool:\n    e = expr.replace(' ', '')\n    return not (e.startswith(('&','|')) or e.endswith(('&','|')) or '&&' in e or '||' in e or '&|' in e or '|&' in e)","typeGuard":null,"tryCatchPattern":"try:\n    node.get_input_keys(state)\nexcept ValueError as e:\n    raise ValueError(f'Bad input expression, check operators: {e}') from e","preventionTips":["Use single-char operators '&'/'|' only","Never build expressions by blind string concatenation; validate before passing"],"tags":["scrapegraphai","node-config","operator-misuse","expression-parsing"],"backgroundTag":"expression-syntax-invalid","analyzedSha":"532dfffbf6ee823a6c9cf8cfedc24a93bf026780","analyzedAt":"2026-08-28T15:19:38.821Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}