unslothai/unsloth · error · ValueError

Auto-download missing models must be true or false.

Error message

Auto-download missing models must be true or false.

What it means

Raised by set_openai_auto_switch in openai_auto_switch_settings.py:319-322 when auto_download is provided and cannot be coerced to bool. Same accepted set as other flags: True/False or the strings 1/true/yes/on and 0/false/no/off (trimmed, case-insensitive). Ints other than via those strings, and unknown tokens, are rejected.

Source

Thrown at studio/backend/utils/openai_auto_switch_settings.py:321

    if media_idle_seconds is not None:
        parsed_media_idle = _coerce_int(media_idle_seconds)
        if parsed_media_idle is None:
            raise ValueError("Media auto-unload idle seconds must be a non-negative integer.")
        if 0 < parsed_media_idle < MIN_AUTO_UNLOAD_IDLE_SECONDS:
            raise ValueError(
                f"Media auto-unload idle seconds must be 0 (off) or at least "
                f"{MIN_AUTO_UNLOAD_IDLE_SECONDS}."
            )
    parsed_keep_kv = None
    if keep_kv is not None:
        parsed_keep_kv = _coerce_bool(keep_kv)
        if parsed_keep_kv is None:
            raise ValueError("Keep KV on idle unload must be true or false.")
    parsed_auto_download = None
    if auto_download is not None:
        parsed_auto_download = _coerce_bool(auto_download)
        if parsed_auto_download is None:
            raise ValueError("Auto-download missing models must be true or false.")
    parsed_api_only = None
    if api_only is not None:
        parsed_api_only = _coerce_bool(api_only)
        if parsed_api_only is None:
            raise ValueError("Auto-unload API-loaded only must be true or false.")
    from storage.studio_db import upsert_app_settings

    updates: dict[str, Any] = {OPENAI_AUTO_SWITCH_SETTING_KEY: parsed_enabled}
    if parsed_idle is not None:
        updates[AUTO_UNLOAD_IDLE_SETTING_KEY] = parsed_idle
    if parsed_media_idle is not None:
        updates[MEDIA_AUTO_UNLOAD_IDLE_SETTING_KEY] = parsed_media_idle
    if parsed_keep_kv is not None:
        updates[AUTO_UNLOAD_KEEP_KV_SETTING_KEY] = parsed_keep_kv
    if parsed_auto_download is not None:
        updates[OPENAI_AUTO_DOWNLOAD_SETTING_KEY] = parsed_auto_download
    if parsed_api_only is not None:
        updates[AUTO_UNLOAD_API_ONLY_SETTING_KEY] = parsed_api_only

View on GitHub (pinned to 203007d190)

Solutions

  1. Pass bool(auto_download) after your own validation
  2. Send JSON booleans from clients
  3. Map 0/1 to False/True explicitly before calling
  4. Omit the parameter to leave the stored value untouched

Example fix

# before
set_openai_auto_switch(enabled=True, auto_download=0)

# after
set_openai_auto_switch(enabled=True, auto_download=False)
Defensive patterns

Strategy: validation

Validate before calling

def to_bool(v) -> bool | None:
    if isinstance(v, bool):
        return v
    if isinstance(v, str):
        n = v.strip().lower()
        if n in {"1", "true", "yes", "on"}: return True
        if n in {"0", "false", "no", "off"}: return False
    return None

if auto_download is not None and to_bool(auto_download) is None:
    raise HTTPException(400, "auto_download must be a boolean")

Type guard

def is_bool_like(v: object) -> bool:
    return isinstance(v, bool) or (
        isinstance(v, str) and v.strip().lower() in {"1","true","yes","on","0","false","no","off"}
    )

Try / catch

try:
    set_openai_auto_switch(enabled=True, auto_download=auto_download)
except ValueError as exc:
    raise HTTPException(400, str(exc)) from exc

Prevention

When it happens

Trigger: set_openai_auto_switch(enabled=True, auto_download=0) — integer zero is rejected even though it 'looks' false. Also auto_download="download", "y", or a list.

Common situations: Frontend sends 0/1 ints for toggles; YAML/JSON config loaders producing ints; scripting around the settings API with truthy values.

Related errors


AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15). Data as JSON: /api/errors/2cc3a98068edd41c. Report an issue: GitHub.