
Instruction Tuning Templates
From Alpaca to Chat. Understand the history of instruction prompting and the specific string templates used to separate instructions from context.
Instruction Tuning Templates: The Evolution of the Prompt
Before we had sophisticated "Role-based" formats like ChatML, we had Templates.
In the early days of LLM instruction following (around the time of the Stanford Alpaca project), we didn't have special model markers for "User" or "Assistant." Instead, we just used clear, structured text headers to help the model distinguish between the instruction, the input, and the expected output.
While modern models prefer ChatML, knowing these templates is essential if you are working with older open-source models or building specialized "Non-Chat" applications like code generators or summarizers.
In this lesson, we will compare the classic Alpaca format with the modern User/Assistant split.
1. The Alpaca Template (Classic)
The Alpaca template was designed for Single-Turn instruction following. It uses a very specific block of text to "prepare" the model for a response.
The Structure:
Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
### Instruction:
{instruction}
### Input:
{input}
### Response:
{response}
Why it works:
It creates a clear, vertical hierarchy. By the time the model generates the text after ### Response:, it has a high "Attention" score on the Instruction and Input blocks. This format is still excellent for tasks like Data Cleaning, Translation, and Summarization.
2. The User/Assistant Template (Modern)
As models became "Chat" focused, the templates shifted to reflect a dialogue. This is what ChatML (from Lesson 1) is converted into "under the hood."
The Structure:
USER: {prompt}
ASSISTANT: {response}
Or, more formally in models like Llama:
[INST] {prompt} [/INST] {response}
Why it works:
It is more token-efficient than the Alpaca template. It doesn't waste hundreds of tokens on the "Below is an instruction..." boilerplate. It assumes the model already knows how to follow instructions and just needs a role marker.
Technical Comparison: Alpaca vs. User/Assistant
| Feature | Alpaca | User/Assistant |
|---|---|---|
| History | Stanford Alpaca (Llama 1 era) | Llama 2 / Llama 3 / Mistral era |
| Turns | Primarily Single-Turn | Multi-Turn native |
| Complexity | High (Heavy boilerplate) | Low (Lightweight markers) |
| Best used for... | Fine-tuning base models for specific single-shot tasks. | Fine-tuning chat models or agents. |
Visualizing the Formatting Chain
graph LR
A["Raw JSON Data"] --> B["Template Engine"]
B --> C["Formatted String"]
C --> D["Tokenizer"]
D --> E["Integer IDs (Model Input)"]
subgraph "The Alpaca Path"
B1["Alpaca Template"]
end
subgraph "The Chat Path"
B2["User/Assistant Template"]
end
Implementation: Applying a Template in Python
You should never manually format your strings if you can help it. Instead, you should use a Template Function.
def format_alpaca(example):
"""
Formats a single dataset example into the Alpaca template.
"""
if example.get("input"):
return f"""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
### Instruction:
{example['instruction']}
### Input:
{example['input']}
### Response:
{example['output']}"""
else:
return f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
### Instruction:
{example['instruction']}
### Response:
{example['output']}"""
# Usage
data = {"instruction": "Capital of France", "input": "", "output": "Paris"}
print(format_alpaca(data))
The Transition: "Instruction" -> "System"
In modern templates, the Instruction part of Alpaca has essentially become the System role in ChatML.
- Alpaca Instruction: "Act as a helpful accountant."
- Modern System Prompt:
{"role": "system", "content": "Act as a helpful accountant."}
When upgrading an old dataset to a new model, you usually map the Instruction to the System role and the Input to the User role.
Summary and Key Takeaways
- Templates are the final string layout that the model "sees."
- Alpaca is highly structured and great for single-turn task specialization.
- User/Assistant is streamlined and the standard for conversational AI.
- Token Efficiency: Modern templates save cost by removing excessive boilerplate.
- Golden Rule: Match your fine-tuning template to the template the base model was originally trained with for the best results.
In the next lesson, we will look at Formatting for OpenAI vs Bedrock vs Vertex AI, providing the exact JSON schemas for the major cloud providers.
Reflection Exercise
- Look at the Alpaca template again. If you were a model, why would the words
### Response:be important? (Hint: Think about what the model should generate after seeing those tokens). - Why did the industry move away from long boilerplate like "Below is an instruction..."? (Hint: Cost and Context Window).
SEO Metadata & Keywords
Focus Keywords: Alpaca Template format, Instruction Tuning vs Chat Tuning, User Assistant Prompt Template, fine-tuning boilerplate, SFT template examples. Meta Description: Explore the evolution of instruction tuning templates. Compare the classic Alpaca structure with modern User/Assistant formats and learn how to format your data for maximum model attention.