{"record":{"id":"1168162a255b482f","repo":"xtekky/gpt4free","slug":"unknown-variable-in-condition-root-r","errorCode":null,"errorMessage":"Unknown variable in condition: {root!r}","messagePattern":"Unknown variable in condition: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"g4f/providers/config_provider.py","lineNumber":281,"sourceCode":"        raise ValueError(\"Unexpected end of condition expression\")\n\n    kind, value = tokens[pos]\n    pos += 1\n\n    if kind == \"float\":\n        return float(value), pos\n    elif kind == \"int\":\n        return int(value), pos\n    elif kind == \"id\":\n        # Legacy alias: \"get_quota.balance\" → \"quota.balance\"\n        if value == \"get_quota.balance\":\n            value = \"quota.balance\"\n\n        # Resolve dotted paths: \"quota.credits.remaining\", \"balance\", etc.\n        parts = value.split(\".\")\n        root = parts[0]\n        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","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/providers/config_provider.py#L263-L299","documentation":"ValueError from condition variable resolution in config_provider: the condition referenced a dotted variable whose root name is not in the evaluation variables dict (quota, error_count, etc.). The message shows the unresolved root. Only variables exposed by evaluate_condition can be used in provider conditions.","triggerScenarios":"A config.yaml condition like 'credits > 0' or 'user.tier == 1' where the root ('credits', 'user') is not a known variable; only roots such as 'quota' (and the legacy alias get_quota.balance, plus error/balance style roots the evaluator provides) are resolvable.","commonSituations":"Copying conditions from another tool's config; typos in variable names; newer config syntax documented for a different g4f version; referencing API-response fields that are nested under quota but written at top level.","solutions":["Rewrite the condition to use supported roots — e.g. 'quota.credits.remaining > 0' instead of 'credits.remaining > 0'.","Print the quota dict the provider returns (provider.get_quota()) to see the exact keys available under 'quota'.","Remove the condition entirely if you don't need quota gating — a provider without a condition is always eligible.","Check g4f docs/changelog for the current condition variable names for your version."],"exampleFix":"# before (config.yaml)\ncondition: \"credits.remaining > 0\"\n\n# after\ncondition: \"quota.credits.remaining > 0\"","handlingStrategy":"validation","validationCode":"KNOWN_ROOTS = {'quota', 'error_count'}  # roots the evaluator provides\nused_roots = {c.split('.')[0] for c in my_conditions}\nunknown = used_roots - KNOWN_ROOTS\nif unknown:\n    raise ValueError(f'unknown condition variables: {sorted(unknown)}')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use evaluate_condition(cond, sample_vars, 0) as a CI check on config.yaml.","Reference fields via the quota dict returned by provider.get_quota().","Remember the legacy alias get_quota.balance is auto-rewritten to quota.balance."],"tags":["config","yaml","condition-parser","unknown-variable","g4f"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}