{"record":{"id":"fc04cff2bf07954a","repo":"hiyouga/LlamaFactory","slug":"template-data-args-template-does-not-exist","errorCode":null,"errorMessage":"Template {data_args.template} does not exist.","messagePattern":"Template (.+?) does not exist\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/llamafactory/data/template.py","lineNumber":683,"sourceCode":"        replace_jinja_template=False,\n        enable_thinking=True,\n        preserve_thinking=False,\n        mm_plugin=get_mm_plugin(name=\"base\"),\n    )\n\n\ndef get_template_and_fix_tokenizer(tokenizer: \"PreTrainedTokenizer\", data_args: \"DataArguments\") -> \"Template\":\n    r\"\"\"Get chat template and fixes the tokenizer.\"\"\"\n    if data_args.template is None:\n        if isinstance(tokenizer.chat_template, str):\n            logger.warning_rank0(\"`template` was not specified, try parsing the chat template from the tokenizer.\")\n            template = parse_template(tokenizer)\n        else:\n            logger.warning_rank0(\"`template` was not specified, use `empty` template.\")\n            template = TEMPLATES[\"empty\"]  # placeholder\n    else:\n        if data_args.template not in TEMPLATES:\n            raise ValueError(f\"Template {data_args.template} does not exist.\")\n\n        template = TEMPLATES[data_args.template]\n\n    if data_args.train_on_prompt and template.efficient_eos:\n        raise ValueError(\"Current template does not support `train_on_prompt`.\")\n\n    if data_args.tool_format is not None:\n        logger.info_rank0(f\"Using tool format: {data_args.tool_format}.\")\n        default_slots = [\"{{content}}\"] if template.efficient_eos else [\"{{content}}\", {\"eos_token\"}]\n        template.format_function = FunctionFormatter(slots=default_slots, tool_format=data_args.tool_format)\n        template.format_tools = ToolFormatter(tool_format=data_args.tool_format)\n\n    if data_args.default_system is not None:\n        logger.info_rank0(f\"Using default system message: {data_args.default_system}.\")\n        template.default_system = data_args.default_system\n\n    if isinstance(template, ReasoningTemplate):\n        logger.warning_rank0(","sourceCodeStart":665,"sourceCodeEnd":701,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/src/llamafactory/data/template.py#L665-L701","documentation":"get_template_and_fix_tokenizer looks up data_args.template in the global TEMPLATES dict and raises ValueError when the name is unknown. This runs at the very start of data preprocessing, so a typo'd or unavailable template fails fast before any data work.","triggerScenarios":"Setting template: <name> in the YAML to a name that is not registered — typos ('llama3' vs 'llama3_1' etc.), custom templates registered in a different process, or template names removed/renamed across LlamaFactory versions; loading a dataset with template metadata referencing a missing entry.","commonSituations":"Upgrading LlamaFactory and old YAML configs reference renamed templates; writing template names from memory instead of copying from template.py's TEMPLATES keys; forgetting to run the register_template snippet in the training script that uses it.","solutions":["List available names: python -c \"from llamafactory.data.template import TEMPLATES; print(sorted(TEMPLATES))\" and copy the exact key.","Fix the typo in the template field of your YAML/dataset_info.json.","If the template is custom, ensure register_template runs in the same process before training (e.g. put it in the entry script), or port the definition to the new API after a version upgrade."],"exampleFix":"# before\ntemplate: llama_3\n\n# after\ntemplate: llama3","handlingStrategy":"validation","validationCode":"from llamafactory.data.template import TEMPLATES\n\nassert my_template_name in TEMPLATES, f\"{my_template_name} not in {sorted(TEMPLATES)}\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Copy template names verbatim from the TEMPLATES keys, not from memory.","Pin the LlamaFactory version so template names in configs stay valid.","Register custom templates in the same process that consumes them."],"tags":["template","config","typo"],"backgroundTag":null,"analyzedSha":"f28afaf6355af515454dfb16c97d728307c93897","analyzedAt":"2026-08-14T21:57:28.298Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}