← the late compiler
C_000063 · llms and generative ai · advanced

Chat Format Templates

The role-tagged structure — system, user, assistant — that conversational models were trained to expect.

Step 1 of 4

In words

What it is, why it matters, and what it is like.

Why am I learning this?

Before you ever fine-tune a conversational model, you must shape your data into the exact role-tagged structure the model was trained on. Get this wrong and the model will look broken — rambling, ignoring instructions, refusing to answer — when the real fault is a mismatched template. This concept is the gate to everything in Fine-Tuning: Instruction Tuning, LoRA and QLoRA, DPO, and every one of your neighbouring notes that assumes data already sits in the right chat format. Master the template first and every later step — from a simple fine-tune to a multi-tenant adapter service — will behave the way the books say it should.

The idea, in plain terms

Modern chatbots are not programmed to hold conversations. They are trained on millions of transcripts that all follow the same invisible skeleton: each line is tagged with a role. There is a system role that sets the ground rules, a user role that speaks the actual request, and an assistant role that gives the answer. The model does not learn what a 'user' is from a dictionary — it learns by seeing the pattern of who talks when, and what the correct response looks like after each kind of prompt. Once training is complete, the same skeleton is used at inference time: you hand the model a text that begins with <|system|>, then <|user|>, and the model continues with the <|assistant|> line because that is the only continuation it has ever seen work.

An analogy

Think of a model as a drama school student who has learned every play ever written, but the plays are all written in the same rigid format: a cast list at the top, then lines labelled 'King:', 'Queen:', 'Fool:'. If you hand this student a script that omits the cast list and the labels, they will flounder — not because they lack acting ability, but because they have never seen a script in that shape. The chat format template is the script format. For one model it might be 'You: ... Assistant: ...', for another '<|user|> ... <|assistant|>'. The rules of the script are exactly the rules the drama student memorised during training. If you give them a different formatting convention — say, a script with no labels at all — they cannot call up what they learned, because their knowledge is welded to the format. The format is not a superficial wrapper; it is part of the language. Where the analogy stops holding: a drama student can improvise and adapt to an unlabelled script because they have social intuition. A language model has no such intuition. It only knows the patterns in its training data. If the input strays from the format, the model does not 'figure it out' — it produces something, often odd, because it is completing a pattern that was not trained.

Definition

A chat format template is the exact sequence of role tags — typically system, user, and assistant — that a conversational model expects to see wrapped around every message, because that is the only structure it was trained on.

Where this sits

You have not yet studied any other concepts, so everything here is new. But this idea connects directly ahead to your first fine-tuning steps. In Instruction Tuning, you will take raw instruction-response pairs and re-serialise them into the chat template before training a single weight. In LoRA and QLoRA, the adapter learns on data that must already be in this format — otherwise the adapter is learning the wrong associations. Even your note on Multi-Tenant Adapter Serving presumes the template is handled correctly per request. If the template is wrong, the model's behaviour degrades in ways that look like a weak model, so debugging begins here. Your book 'Fine-Tuning with Python' is emphatic: data must be shaped into the model's chat format before tuning, or nothing downstream works.

Signal from the Frontier

Get the next essay on mind, machine, and meaning

Essays at the intersection of AI, philosophy, and Indian governance. No promotional content.

We'll send a one-click sign-in link to confirm. No password needed.

Views expressed are personal and do not represent the Government of India or the Government of Uttarakhand.