LlamaFactory Prompt Templates: Complete Guide to 80+ Built-In Chat Formats
LlamaFactory supports over 80 built-in prompt templates including Alpaca, LLaMA-2, LLaMA-3, ChatML, Qwen, and Gemma, all registered in src/llamafactory/data/template.py and selectable via CLI, YAML, Web UI, or Python API.
LlamaFactory is a unified open-source framework for fine-tuning large language models. Understanding the prompt templates supported by LlamaFactory is essential because these templates define how multi-turn conversations are serialized into the token sequences that models actually process during training and inference.
What Are LlamaFactory Prompt Templates?
A prompt template in LlamaFactory is a Python class that encodes conversation history—system messages, user turns, and assistant responses—into a formatted string compatible with a specific model family.
In src/llamafactory/data/template.py, each template is registered via the register_template function, which stores template objects in the global dictionary TEMPLATES. The string name passed to register_template becomes the template identifier used throughout the framework.
# From src/llamafactory/data/template.py
@register_template(name="llama3")
def get_llama3_template() -> Template:
return Template(
format_user=StringFormatter(slots=["<|start_header_id|>user<|end_header_id|>\n\n{{content}}<|eot_id|>"]),
format_assistant=StringFormatter(slots=["<|start_header_id|>assistant<|end_header_id|>\n\n{{content}}<|eot_id|>"]),
format_system=StringFormatter(slots=["<|start_header_id|>system<|end_header_id|>\n\n{{content}}<|eot_id|>"]),
stop_words=["<|eot_id|>"],
)
Complete List of Supported Prompt Templates
LlamaFactory organizes its 80+ templates by model family and use case. Below are the most commonly used identifiers, with the full registry available in src/llamafactory/data/template.py.
Classic Instruction Formats
These templates follow the original "Instruction / Response" paradigm popularized by early fine-tuning datasets.
-
alpaca– The classic Alpaca format with### Instruction:and### Response:blocks (line 653 intemplate.py) -
vicuna– Vicuna-styleUSER:andASSISTANT:turns with optional system messages (line 1523) -
default– Minimal fallback format usingHuman:andAssistant:prefixes (line 834)
Modern Chat Formats
These templates implement the specific token conventions required by contemporary foundation models.
llama2– Meta LLaMA-2 format with[INST]and[/INST]tokens, including system message injection via<<SYS>>(line 1313)llama3– LLaMA-3 format with<|start_header_id|>and<|eot_id|>tokens, supporting reasoning tags (line 1331)mistral_small– Mistral Small format using[INST] … [/INST]with efficient EOS handling (line 1702)gemma– Google Gemma format with<start_of_turn>and<end_of_turn>tags (line 937)
Multilingual and Specialized Templates
Templates optimized for specific languages or model families with unique tokenization requirements.
chatml– HuggingFace ChatML format using<|im_start|>userand<|im_end|>tokens
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →