Instruction Format › Summary

Michael BrenndoerferDecember 18, 20252 min read
Language AI HandbookAll chapters
Part 36 of 67Instruction Tuning
Chapter 269Instruction Format › Summary
Reading section 13 of 14 · Summary · 2 minSection 13 of 14 · 2 min

Book contents

Section 13 of 14 · 2 min read

Instruction Format › SummaryOne section · Sections in this chapter13 / 14 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Instruction formats give the structure that allows language models to parse conversations and generate correct responses. The design choices made in a template affect how the model parses inputs, what behavioral capabilities emerge from training, how reliable the deployed system is to adversarial or unusual inputs, and how flexibly the model can be deployed across different applications.

The key concepts we covered include:

  • Prompt templates wrap instruction-response pairs with consistent delimiters that the model learns to recognize. Whether using natural language markers like ### Instruction: or special tokens, consistency between training and inference is needed, and even minor formatting deviations can cause measurable degradation.

  • Role definitions separate system context from user input and assistant output. This three-role structure lets multi-turn conversations, behavioral customization through system prompts, and appropriate loss masking during training. Extended roles like tool and thinking support more advanced capabilities in modern models.

  • System messages establish persistent behavioral context that influences all subsequent responses. They allow the same base model to behave differently across applications without retraining, and their effectiveness depends on training data that presents diverse system-message styles and constraints.

  • Chat templates standardize how conversations become token sequences. Different model families use different formats: ChatML for many OpenAI-style models, [INST] markers for Llama 2 and Mistral, dedicated header tokens for Llama 3, and various others. Using the tokenizer's apply_chat_template method ensures correct formatting for each model and protects against manual formatting errors.

  • Training data preparation requires identifying assistant tokens for loss computation while masking out prompts, system messages, and format tokens. The prompt-continuation split technique reliably locates this boundary. The loss fraction problem, where short responses contribute disproportionately little gradient signal, deserves careful attention when designing the training data pipeline.

  • Custom templates using Jinja2 syntax allow full control over format design for novel use cases, but they require careful special-token management to ensure structural markers are single tokens rather than multi-token sequences.

The next chapter on Instruction Tuning Training will cover how to train models using these formatted datasets, including learning rate schedules, batch construction strategies, and convergence monitoring.