Roles in a chat training example: pick the three that are standard.
The three core chat roles are system (behaviour), user (human turn), and assistant (model turn). Tool and function are optional extensions for tool calling.
Picture a script for a small play. The director has stage directions at the top describing how the actors should behave throughout the scene. The audience member speaks lines aloud. The actor on stage responds. Three speaking parts, each with its own role label. In a chat training example the director is the system message, the audience member is the user, and the actor is the assistant. The model is being trained to play one specific role, the actor, and to take direction from the system message while responding to the user. Some plays add a stagehand who reports results from off-stage; that is the optional tool role. The core trio always shows up.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Roles in a chat training example are the structural backbone of every modern instruction-tuned model. The convention is simple, the OpenAI chat-completions schema chose system, user, and assistant as the three canonical labels, and the rest of the ecosystem fell in line, but the consequences run deep. The role tags drive prompt masking, conversation rendering, tool-call serialisation, and a half-dozen other production concerns that beginners rarely see.
This deep dive separates four layers. First, the three core roles and what each represents semantically. Second, the optional fourth role for tool calling and how it varies across providers. Third, the serialisation layer: how the role list becomes actual tokens via per-model chat templates. Fourth, the loss-masking machinery that uses role tags to compute gradient only on assistant turns.
The headline is straightforward. system sets behaviour, user is the human, assistant is the model. Loss flows only on assistant. Templates wrap roles in model-specific tokens. Tool extensions exist but are not portable across providers. Getting any of these wrong, mixing templates, including user tokens in the loss, treating system as optional, produces broken fine-tunes in subtle ways.
A common source of confusion deserves up-front treatment. Roles are not the same as dataset record field names. Alpaca's instruction / input / output, Dolly's instruction / context / response, and the old GPT-3 prompt / completion are flat record schemas. They describe the columns in a CSV or JSONL file. Roles describe the speakers in a conversation. Modern loaders convert flat record formats into role-tagged messages before training. The two layers serve different purposes and live at different points in the pipeline.
The three canonical roles
system
The system role carries behavioural setup. Persona descriptions, response style, safety constraints, format expectations, available tools. The system message typically appears once at the top of a conversation and stays in scope for the entire dialogue.
In practice, the system message is where teams encode the model's character. A customer-support model has a system message about being helpful and citing policy. A code-completion model has a system message about returning runnable code in a specified language. The model conditions on every token of the system message but never generates it during training.
user
The user role marks turns from the human. In a multi-turn conversation, user and assistant turns alternate after the initial system message. User content can include arbitrary text, code, structured data, or references to attached files (depending on the model's modality support).
During SFT the user tokens are conditioned on but masked from the loss. This is critical: training the model to generate user-like text would teach it to play both sides of the conversation, which is a documented failure mode.
assistant
The assistant role marks turns from the model. This is the only role whose tokens contribute to the SFT loss. The trainer's job during SFT is to teach the model to produce appropriate assistant tokens given the preceding system and user context.
A single conversation might have multiple assistant turns if it includes back and forth across several user messages. All assistant turns contribute to the loss; the trainer does not privilege the first or last.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
| Role | Who it represents | Loss applied? |
|---|---|---|
| system | Behavioural setup / persona | No, conditioned on |
| user | Human turn | No, conditioned on |
| assistant | Model turn | Yes |
| tool (optional) | External tool output | Usually no |
Real products, models, and research that use this idea.
- OpenAI chat-completions API was the original system/user/assistant schema, adopted by every modern provider.
- Llama 4 Maverick uses the Llama-3 chat template with system/user/assistant plus tool, marked with `<|start_header_id|>` style tokens.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow does Hugging Face's apply_chat_template actually work?
Each tokenizer ships a Jinja template string that maps a list of {role, content} dicts to a serialised token stream with the model's expected role markers (Llama-3 headers, ChatML im_start, Mistral INST blocks, etc.). The function renders the template and returns either a string or a token id list.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Confusing roles with dataset record field names. Alpaca-style instruction/input/output and old GPT-3 prompt/completion are flat record schemas, not message-role labels.
60 second bullets to scan on the way to the call.
The three canonical roles and what each represents
Where the system message lives in the conversation order
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.