hiyouga/LlamaFactory · error · ValueError

Template {data_args.template} does not exist.

Error message

Template {data_args.template} does not exist.

What it means

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.

Source

Thrown at src/llamafactory/data/template.py:683

        replace_jinja_template=False,
        enable_thinking=True,
        preserve_thinking=False,
        mm_plugin=get_mm_plugin(name="base"),
    )


def get_template_and_fix_tokenizer(tokenizer: "PreTrainedTokenizer", data_args: "DataArguments") -> "Template":
    r"""Get chat template and fixes the tokenizer."""
    if data_args.template is None:
        if isinstance(tokenizer.chat_template, str):
            logger.warning_rank0("`template` was not specified, try parsing the chat template from the tokenizer.")
            template = parse_template(tokenizer)
        else:
            logger.warning_rank0("`template` was not specified, use `empty` template.")
            template = TEMPLATES["empty"]  # placeholder
    else:
        if data_args.template not in TEMPLATES:
            raise ValueError(f"Template {data_args.template} does not exist.")

        template = TEMPLATES[data_args.template]

    if data_args.train_on_prompt and template.efficient_eos:
        raise ValueError("Current template does not support `train_on_prompt`.")

    if data_args.tool_format is not None:
        logger.info_rank0(f"Using tool format: {data_args.tool_format}.")
        default_slots = ["{{content}}"] if template.efficient_eos else ["{{content}}", {"eos_token"}]
        template.format_function = FunctionFormatter(slots=default_slots, tool_format=data_args.tool_format)
        template.format_tools = ToolFormatter(tool_format=data_args.tool_format)

    if data_args.default_system is not None:
        logger.info_rank0(f"Using default system message: {data_args.default_system}.")
        template.default_system = data_args.default_system

    if isinstance(template, ReasoningTemplate):
        logger.warning_rank0(

View on GitHub (pinned to f28afaf635)

Solutions

  1. List available names: python -c "from llamafactory.data.template import TEMPLATES; print(sorted(TEMPLATES))" and copy the exact key.
  2. Fix the typo in the template field of your YAML/dataset_info.json.
  3. 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.

Example fix

# before
template: llama_3

# after
template: llama3
Defensive patterns

Strategy: validation

Validate before calling

from llamafactory.data.template import TEMPLATES

assert my_template_name in TEMPLATES, f"{my_template_name} not in {sorted(TEMPLATES)}"

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of hiyouga/LlamaFactory@f28afaf635 (2026-08-14). Data as JSON: /api/errors/fc04cff2bf07954a. Report an issue: GitHub.