{"record":{"id":"f5d5ccc5bb30fe75","repo":"huggingface/transformers","slug":"x-is-not-a-value-that-can-be-converted-to-a-bool","errorCode":null,"errorMessage":"{x} is not a value that can be converted to a bool.","messagePattern":"(.+?) is not a value that can be converted to a bool\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/cli/add_new_model_like.py","lineNumber":682,"sourceCode":"                valid_answer = False\n        else:\n            valid_answer = True\n\n        if not valid_answer:\n            print(fallback_message)\n\n    return answer\n\n\ndef convert_to_bool(x: str) -> bool:\n    \"\"\"\n    Converts a string to a bool.\n    \"\"\"\n    if x.lower() in [\"1\", \"y\", \"yes\", \"true\"]:\n        return True\n    if x.lower() in [\"0\", \"n\", \"no\", \"false\"]:\n        return False\n    raise ValueError(f\"{x} is not a value that can be converted to a bool.\")\n\n\ndef get_user_input():\n    \"\"\"\n    Ask the user for the necessary inputs to add the new model.\n    \"\"\"\n    from transformers.models.auto.configuration_auto import CONFIG_MAPPING_NAMES\n\n    model_types = list(CONFIG_MAPPING_NAMES.keys())\n\n    # Get old model type\n    valid_model_type = False\n    while not valid_model_type:\n        old_model_type = input(\n            \"What model would you like to duplicate? Please provide it as lowercase, e.g. `llama`): \"\n        )\n        if old_model_type in model_types:\n            valid_model_type = True","sourceCodeStart":664,"sourceCodeEnd":700,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/cli/add_new_model_like.py#L664-L700","documentation":"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?'.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Answer prompts with y/n/yes/no/true/false/1/0 exactly","When scripting, feed a here-string of valid answers in prompt order, e.g. printf 'y\\nn\\n'","Re-run the command and answer each prompt with a supported token"],"exampleFix":"# before\necho 'maybe' | transformers add-new-model-like ...\n\n# after\nprintf 'y\\ny\\nn\\n' | transformers add-new-model-like ...","handlingStrategy":"validation","validationCode":"VALID = {\"1\", \"y\", \"yes\", \"true\", \"0\", \"n\", \"no\", \"false\"}\nanswer = answer.strip().lower()\nif answer not in VALID:\n    answer = \"y\"  # or re-prompt","typeGuard":"def is_bool_answer(x: str) -> bool:\n    return x.strip().lower() in {\"1\", \"y\", \"yes\", \"true\", \"0\", \"n\", \"no\", \"false\"}","tryCatchPattern":null,"preventionTips":["Feed only y/n-style tokens when scripting the command","Prefer `yes n |` or printf pipelines with exact answer sequences","Answer prompts explicitly rather than pressing Enter on empty input"],"tags":["cli","user-input","bool-parsing","valueerror","developer-tooling"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}