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.
Detailed answer & concept explanation~7 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
5 min: the three roles + the system / user / assistant trio + loss masking on assistant only + tool as the optional fourth role + chat templates + the Alpaca vs role-schema confusion.
| 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.
- Qwen 3.5 ships ChatML-style markers (`<|im_start|>`, `<|im_end|>`) with the same three core roles plus optional tool.
- Anthropic's Claude API uses a similar system/user/assistant schema with system as a separate top-level field rather than a message.
- Hugging Face TRL's SFTTrainer auto-detects chat-formatted data with role keys and applies the model's chat template before training.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow does Hugging Face's apply_chat_template actually work?
QWhy does SFT mask system and user tokens from the loss?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes 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.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.