xtekky/gpt4free · error · ValueError
Unexpected end of condition expression
Error message
Unexpected end of condition expression
What it means
ValueError from the recursive-descent condition parser in config_provider: while parsing a config.yaml provider condition, _parse_atom (or its callers) ran out of tokens before completing the expression. This is a syntax error in the condition string — e.g. it ends with a dangling operator or an incomplete comparison.
Source
Thrown at g4f/providers/config_provider.py:263
if pos < len(tokens) and tokens[pos][0] == "rp":
pos += 1 # consume ')'
return val, pos
left_val, pos = _parse_atom(tokens, pos, variables)
if pos < len(tokens) and tokens[pos][0] == "op":
op_str = tokens[pos][1]
pos += 1
right_val, pos = _parse_atom(tokens, pos, variables)
return _OPS[op_str](left_val, right_val), pos
# Bare value – treat as truthy
return bool(left_val), pos
def _parse_atom(tokens, pos, variables):
if pos >= len(tokens):
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}")View on GitHub (pinned to 973504e177)
Solutions
- Open config.yaml and complete the malformed condition: every operator needs a right-hand operand (e.g. 'quota.credits.remaining > 0').
- Validate YAML quoting — keep conditions on one line or use quoted folded scalars so tokens are not lost.
- Run a quick parse check: from g4f.providers.config_provider import evaluate_condition; evaluate_condition('<condition>', {}, 0) to test in isolation.
- Comment out the offending provider entry to restore service, then fix and re-enable.
Example fix
# before (config.yaml) condition: "quota.credits.remaining >" # after condition: "quota.credits.remaining > 0"
Defensive patterns
Strategy: validation
Validate before calling
from g4f.providers.config_provider import evaluate_condition
for cond in my_conditions: # gathered from config.yaml before deployment
try:
evaluate_condition(cond, {'quota': {'balance': 1.0}}, 0)
except ValueError as e:
raise ValueError(f'bad config.yaml condition {cond!r}: {e}') from e Prevention
- Lint every condition in config.yaml with evaluate_condition at startup.
- Keep conditions on a single YAML line, fully quoted.
- Every operator needs a right-hand operand; no trailing operators.
When it happens
Trigger: A config.yaml provider entry has a condition like 'quota.credits.remaining >' or 'balance ==' (or an empty operand after an operator); evaluate_condition tokenizes it and _parse_atom hits pos >= len(tokens).
Common situations: Hand-editing config.yaml and truncating a condition; YAML folding/quoting splitting a condition string; upgrading g4f and older condition syntax no longer parsing to a complete token stream.
Related errors
- Unknown variable in condition: {root!r}
- 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/3b5005aff70d8c1a.
Report an issue: GitHub.