huggingface/transformers · error · ArgumentTypeError

Truthy value expected: got {v} but expected one of yes/no, t

Error message

Truthy value expected: got {v} but expected one of yes/no, true/false, t/f, y/n, 1/0 (case insensitive).

What it means

Error "Truthy value expected: got {v} but expected one of yes/no, true/false, t/f, y/n, 1/0 (case insensitive)." thrown in huggingface/transformers.

Source

Thrown at src/transformers/hf_argparser.py:44

from typing import Any, Literal, NewType, Union, get_type_hints

import yaml


DataClass = NewType("DataClass", Any)
DataClassType = NewType("DataClassType", Any)


# From https://stackoverflow.com/questions/15008758/parsing-boolean-values-with-argparse
def string_to_bool(v):
    if isinstance(v, bool):
        return v
    if v.lower() in ("yes", "true", "t", "y", "1"):
        return True
    elif v.lower() in ("no", "false", "f", "n", "0"):
        return False
    else:
        raise ArgumentTypeError(
            f"Truthy value expected: got {v} but expected one of yes/no, true/false, t/f, y/n, 1/0 (case insensitive)."
        )


def make_choice_type_function(choices: list) -> Callable[[str], Any]:
    """
    Creates a mapping function from each choices string representation to the actual value. Used to support multiple
    value types for a single argument.

    Args:
        choices (list): List of choices.

    Returns:
        Callable[[str], Any]: Mapping function from string representation to actual value for each choice.
    """
    str_to_choice = {str(choice): choice for choice in choices}
    return lambda arg: str_to_choice.get(arg, arg)

View on GitHub (pinned to a597f97485)

Solutions

  1. Pass a boolean or one of yes/no, true/false, t/f, y/n, 1/0 for this argument.
  2. Quote or correct the CLI value so it parses as a truthy string.

When it happens

Trigger: Raised in HfArgumentParser string_to_bool conversion when a CLI string is not one of yes/no/true/false/t/f/y/n/1/0.

Common situations: Passing an arbitrary string for a boolean dataclass field on the command line, e.g. --do_train maybe.


AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14). Data as JSON: /api/errors/60342bc031f2ebf3. Report an issue: GitHub.