openai/whisper · error · ValueError

Expected one of {set(str2val.keys())}, got {string}

Error message

Expected one of {set(str2val.keys())}, got {string}

What it means

str2bool is the argparse `type` used for boolean CLI flags such as --verbose, --condition_on_previous_text, and --fp16. It accepts only the exact strings 'True' and 'False' (case-sensitive); anything else — 'true', '1', 'yes', 'false' — raises ValueError, which argparse reports as 'invalid str2bool value'.

Source

Thrown at whisper/utils.py:34

else:

    def make_safe(string):
        # utf-8 can encode any Unicode code point, so no need to do the round-trip encoding
        return string


def exact_div(x, y):
    assert x % y == 0
    return x // y


def str2bool(string):
    str2val = {"True": True, "False": False}
    if string in str2val:
        return str2val[string]
    else:
        raise ValueError(f"Expected one of {set(str2val.keys())}, got {string}")


def optional_int(string):
    return None if string == "None" else int(string)


def optional_float(string):
    return None if string == "None" else float(string)


def compression_ratio(text) -> float:
    text_bytes = text.encode("utf-8")
    return len(text_bytes) / len(zlib.compress(text_bytes))


def format_timestamp(
    seconds: float, always_include_hours: bool = False, decimal_marker: str = "."
):

View on GitHub (pinned to 5f86d1d863)

Solutions

  1. Use exactly 'True' or 'False': whisper audio.mp3 --verbose False
  2. Omit the flag to accept the default shown in --help
  3. In scripts, normalize first: FLAG=$([ "$FLAG" = "true" ] && echo True || echo False)

Example fix

# before
whisper audio.mp3 --verbose true --fp16 0  # invalid str2bool value

# after
whisper audio.mp3 --verbose False --fp16 False
Defensive patterns

Strategy: validation

Validate before calling

def cli_bool(v: str) -> str:
    return "True" if str(v).strip().lower() in ("true", "1", "yes") else "False"

Prevention

When it happens

Trigger: whisper audio.mp3 --verbose true (lowercase), --verbose False vs --verbose false, --fp16 0, or a shell script passing $FLAG where FLAG=yes. Any boolean flag with a non-canonical string triggers it during argument parsing.

Common situations: Shell scripts and YAML-driven invocations using lowercase booleans; users expecting flag-style (--verbose) or 0/1 semantics; environment-variable-derived values passed verbatim.

Related errors


AI-assisted analysis of openai/whisper@5f86d1d863 (2026-08-14). Data as JSON: /api/errors/f85976e4bc541ac4. Report an issue: GitHub.