{"record":{"id":"5b0737a9437ccfcf","repo":"sgl-project/sglang","slug":"invalid-predicate-expr-r-e","errorCode":null,"errorMessage":"invalid predicate {expr!r}: {e}","messagePattern":"invalid predicate (.+?): (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/debug_utils/comparator/threshold_dsl.py","lineNumber":67,"sourceCode":"    default_predicate: str,\n) -> str:\n    if not diff_threshold_rules:\n        return default_predicate\n    for rule in diff_threshold_rules:\n        if re.fullmatch(rule.pattern, name):\n            return rule.predicate\n    raise ValueError(\n        f\"tensor {name!r} matched no --diff-threshold pattern \"\n        f\"({[rule.pattern for rule in diff_threshold_rules]}); add a catch-all '.*' rule or a matching pattern.\"\n    )\n\n\n@lru_cache(maxsize=None)\ndef parse_predicate(expr: str) -> CodeType:\n    try:\n        code = compile(expr, \"<predicate>\", \"eval\")\n    except SyntaxError as e:\n        raise ValueError(f\"invalid predicate {expr!r}: {e}\") from e\n    try:\n        eval(code, _EVAL_GLOBALS, dict(_DUMMY_ENV))\n    except Exception as e:\n        raise ValueError(\n            f\"invalid predicate {expr!r}: {e}; allowed names are {ALLOWED_NAMES}.\"\n        ) from e\n    return code\n\n\ndef evaluate_predicate(\n    code: CodeType, *, rel: float, max_abs: float, mean_abs: float\n) -> bool:\n    return bool(\n        eval(\n            code, _EVAL_GLOBALS, {\"rel\": rel, \"max_abs\": max_abs, \"mean_abs\": mean_abs}\n        )\n    )\n","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/debug_utils/comparator/threshold_dsl.py#L49-L85","documentation":"parse_predicate raises this when the predicate expression fails to compile as a Python expression (SyntaxError). Predicates are small boolean expressions like 'rel <= 0.0085' compiled in eval mode, so any Python syntax error (unbalanced quotes, invalid tokens, '=>') triggers this at parse time.","triggerScenarios":"Calling parse_predicate('rel <= ') or parse_diff_threshold_rules with a malformed predicate token; also via compute_diff which parses predicates lazily.","commonSituations":"Typos like '=>' instead of '<=', missing operand, stray characters, or shell mangling of quotes/<= operators in the predicate string.","solutions":["Fix the expression to be valid Python syntax: one comparison over names like rel, abs, max_abs","Check shell quoting — wrap each predicate in single quotes","Test standalone: python -c \"compile('rel <= 0.1','<p>','eval')\""],"exampleFix":"# before\nparse_diff_threshold_rules(['.*','rel => 0.1'])\n# after\nparse_diff_threshold_rules(['.*','rel <= 0.1'])","handlingStrategy":"validation","validationCode":"def predicate_compiles(expr):\n    try:\n        compile(expr, '<predicate>', 'eval')\n        return True\n    except SyntaxError:\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    code = parse_predicate(expr)\nexcept ValueError as e:\n    print(e); sys.exit(2)","preventionTips":["Keep predicates to a single comparison over allowed metric names","Unit-test predicate strings before wiring them into long compare runs"],"tags":["predicate","dsl","syntax-error","eval"],"backgroundTag":"expression-syntax-error","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}