huggingface/transformers · error · ValueError

{x} is not a value that can be converted to a bool.

Error message

{x} is not a value that can be converted to a bool.

What it means

convert_to_bool in the interactive add-new-model-like flow parses yes/no answers from the user. It accepts {1,y,yes,true} as True and {0,n,no,false} as False (case-insensitive) and raises ValueError for anything else. This guards interactive prompts such as 'should this file be added?'.

Source

Thrown at src/transformers/cli/add_new_model_like.py:682

                valid_answer = False
        else:
            valid_answer = True

        if not valid_answer:
            print(fallback_message)

    return answer


def convert_to_bool(x: str) -> bool:
    """
    Converts a string to a bool.
    """
    if x.lower() in ["1", "y", "yes", "true"]:
        return True
    if x.lower() in ["0", "n", "no", "false"]:
        return False
    raise ValueError(f"{x} is not a value that can be converted to a bool.")


def get_user_input():
    """
    Ask the user for the necessary inputs to add the new model.
    """
    from transformers.models.auto.configuration_auto import CONFIG_MAPPING_NAMES

    model_types = list(CONFIG_MAPPING_NAMES.keys())

    # Get old model type
    valid_model_type = False
    while not valid_model_type:
        old_model_type = input(
            "What model would you like to duplicate? Please provide it as lowercase, e.g. `llama`): "
        )
        if old_model_type in model_types:
            valid_model_type = True

View on GitHub (pinned to a597f97485)

Solutions

  1. Answer prompts with y/n/yes/no/true/false/1/0 exactly
  2. When scripting, feed a here-string of valid answers in prompt order, e.g. printf 'y\nn\n'
  3. Re-run the command and answer each prompt with a supported token

Example fix

# before
echo 'maybe' | transformers add-new-model-like ...

# after
printf 'y\ny\nn\n' | transformers add-new-model-like ...
Defensive patterns

Strategy: validation

Validate before calling

VALID = {"1", "y", "yes", "true", "0", "n", "no", "false"}
answer = answer.strip().lower()
if answer not in VALID:
    answer = "y"  # or re-prompt

Type guard

def is_bool_answer(x: str) -> bool:
    return x.strip().lower() in {"1", "y", "yes", "true", "0", "n", "no", "false"}

Prevention

When it happens

Trigger: Answering an interactive prompt with arbitrary text like 'maybe', 'ok', or an empty line; piping unexpected stdin into the command so prompts receive non-boolean input; a stray newline or comment character in scripted input.

Common situations: Running add-new-model-like non-interactively with `echo`/`yes` pipes that emit unsupported tokens; users typing 'Yeah' or 'N/A' at prompts; CI automation feeding wrong answer files.

Related errors


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