xtekky/gpt4free · error · ValueError
Unknown variable in condition: {root!r}
Error message
Unknown variable in condition: {root!r} What it means
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.
Source
Thrown at g4f/providers/config_provider.py:281
raise ValueError("Unexpected end of condition expression")
kind, value = tokens[pos]
pos += 1
if kind == "float":
return float(value), pos
elif kind == "int":
return int(value), pos
elif kind == "id":
# Legacy alias: "get_quota.balance" → "quota.balance"
if value == "get_quota.balance":
value = "quota.balance"
# Resolve dotted paths: "quota.credits.remaining", "balance", etc.
parts = value.split(".")
root = parts[0]
if root not in variables:
raise ValueError(f"Unknown variable in condition: {root!r}")
result = variables[root]
for part in parts[1:]:
if isinstance(result, dict):
result = result.get(part)
if result is None:
result = 0.0
break
else:
raise ValueError(
f"Cannot access field {part!r} on non-dict value "
f"while resolving {value!r}"
)
return float(result) if result is not None else 0.0, pos
else:
raise ValueError(f"Unexpected token {kind!r}={value!r} in condition expression")
View on GitHub (pinned to 973504e177)
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.
Example fix
# before (config.yaml) condition: "credits.remaining > 0" # after condition: "quota.credits.remaining > 0"
Defensive patterns
Strategy: validation
Validate before calling
KNOWN_ROOTS = {'quota', 'error_count'} # roots the evaluator provides
used_roots = {c.split('.')[0] for c in my_conditions}
unknown = used_roots - KNOWN_ROOTS
if unknown:
raise ValueError(f'unknown condition variables: {sorted(unknown)}') Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Unexpected end of condition expression
- Cannot access field {part!r} on non-dict value while resolvi
- Unexpected token {kind!r}={value!r} in condition expression
- Provider not found: {provider_name!r}
- {provider_name} has no supported create method
AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14).
Data as JSON: /api/errors/1168162a255b482f.
Report an issue: GitHub.