{"record":{"id":"0cc0c5f660da76e3","repo":"xtekky/gpt4free","slug":"unexpected-token-kind-r-value-r-in-condition-e","errorCode":null,"errorMessage":"Unexpected token {kind!r}={value!r} in condition expression","messagePattern":"Unexpected token (.+?)=(.+?) in condition expression","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"g4f/providers/config_provider.py","lineNumber":298,"sourceCode":"        if root not in variables:\n            raise ValueError(f\"Unknown variable in condition: {root!r}\")\n\n        result = variables[root]\n        for part in parts[1:]:\n            if isinstance(result, dict):\n                result = result.get(part)\n                if result is None:\n                    result = 0.0\n                    break\n            else:\n                raise ValueError(\n                    f\"Cannot access field {part!r} on non-dict value \"\n                    f\"while resolving {value!r}\"\n                )\n\n        return float(result) if result is not None else 0.0, pos\n    else:\n        raise ValueError(f\"Unexpected token {kind!r}={value!r} in condition expression\")\n\n\ndef evaluate_condition(\n    condition: str,\n    quota: Optional[Dict],\n    error_count: int,\n) -> bool:\n    \"\"\"Evaluate a provider condition string.\n\n    The condition may reference:\n\n    * ``quota``              – the full quota dict returned by ``get_quota()``.\n      Each provider returns its own schema.  Access nested fields with\n      dot-notation, e.g. ``quota.balance``, ``quota.credits.remaining``.\n      Missing keys resolve to ``0.0``.\n    * ``balance``            – shorthand alias for ``quota.balance``.\n      Kept for backward compatibility; equivalent to ``quota.balance``\n      for providers that return ``{\"balance\": float}`` (e.g. PollinationsAI).","sourceCodeStart":280,"sourceCodeEnd":316,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/providers/config_provider.py#L280-L316","documentation":"ValueError from _parse_atom in config_provider: the tokenizer produced a token whose kind is not one of float/int/id at a position where an operand was expected. This means the condition string contains characters the lexer classified as something else (an operator or stray symbol) where a value had to appear.","triggerScenarios":"Conditions with misplaced operators or unsupported syntax reaching an operand slot, e.g. 'quota.balance > > 0', '!!quota', or strings/operators in positions the tiny parser does not support (no parentheses, no and/or in this grammar).","commonSituations":"Writing Python- or SQL-style boolean logic ('quota.a > 0 and quota.b > 0') that this mini-grammar cannot parse; stray punctuation from YAML copy-paste; unquoted special characters being interpreted oddly.","solutions":["Simplify the condition to what the grammar supports: single comparisons between dotted variables and numeric literals.","Remove boolean connectors — combine multiple conditions as separate provider entries or rely on default eligibility.","Re-test the edited condition via evaluate_condition('<cond>', {'quota': {...}}, 0).","Quarantine the broken entry (comment it out) to unblock the rest of config.yaml while you fix it."],"exampleFix":"# before (config.yaml)\ncondition: \"quota.balance > 0 and error_count < 3\"\n\n# after\ncondition: \"quota.balance > 0\"","handlingStrategy":"validation","validationCode":"import re\nOK = re.compile(r'^[A-Za-z_][\\w.]*(==|!=|>=|<=|>|<)\\s*(\\d+(\\.\\d+)?)$')\nbad = [c for c in my_conditions if not OK.match(c.strip())]\nif bad:\n    raise ValueError(f'unsupported condition syntax: {bad}')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Restrict conditions to one comparison between a dotted variable and a number.","No parentheses, and/or, or string literals in this mini-grammar.","Add a config lint step (regex or evaluate_condition) to CI."],"tags":["config","yaml","condition-parser","syntax-error","g4f"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}