sgl-project/sglang · error · ValueError
cannot parse boolean batching config value: {value!r}
Error message
cannot parse boolean batching config value: {value!r} What it means
Boolean-typed optional fields in a rule accept bools and the strings 1/true/yes/y/on and 0/false/no/n/off (case-insensitive). _optional_bool raises when the value is any other string or an unparseable type.
Source
Thrown at python/sglang/multimodal_gen/runtime/managers/dynamic_batch_admission.py:349
def _optional_float(value: Any) -> float | None:
if value is None:
return None
return float(value)
def _optional_bool(value: Any) -> bool | None:
if value is None:
return None
if isinstance(value, bool):
return value
if isinstance(value, str):
lowered = value.strip().lower()
if lowered in ("1", "true", "yes", "y", "on"):
return True
if lowered in ("0", "false", "no", "n", "off"):
return False
raise ValueError(f"cannot parse boolean batching config value: {value!r}")
View on GitHub (pinned to 0132848349)
Solutions
- Use a real JSON boolean true/false
- If a string is required, use one of: 1/true/yes/y/on or 0/false/no/n/off
Example fix
// before
{"model": "x", "max_batch_size": 4, "some_flag": "enabled"}
// after
{"model": "x", "max_batch_size": 4, "some_flag": true} Defensive patterns
Strategy: validation
Validate before calling
BOOL_STR = {"1","true","yes","y","on","0","false","no","n","off"}
def ok_bool(v):
return isinstance(v, bool) or (isinstance(v, str) and v.strip().lower() in BOOL_STR) Type guard
def is_parseable_bool(v) -> bool:
return isinstance(v, bool) or (isinstance(v, str) and v.strip().lower() in {"1","true","yes","y","on","0","false","no","n","off"}) Prevention
- Prefer real JSON booleans over string forms in config files
When it happens
Trigger: A rule field parsed via _optional_bool with a value like "enabled", "maybe", or an int like 2 (non-bool, non-recognized string).
Common situations: Config generated from YAML where booleans were quoted arbitrarily; env-var-style values like "TRUE " handled fine but custom words like "enable" are not.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- batching config rule requires max_batch_size
- batching config rule cannot set both model and model_contain
- batching config rule requires model or model_contains
- batching config rule max_batch_size must be >= 1
- batching config rule max_cost must be > 0
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/0490ed10da6500c0.
Report an issue: GitHub.