Message roles are the labels that mark each message in a conversation with a chat model as coming from a specific source, typically system, user, assistant or tool. In language models built for dialogue, the role tells the model who is speaking, which instructions carry the most weight and which text it produced itself. Roles turn a flat stream of text into a structured conversation that the model can follow reliably across many turns.
Developers usually meet message roles through a chat completion API, where a request is a list of role-tagged messages rather than a single prompt string. Behind the interface, a chat template converts that list into tokens with special delimiter tokens, so the role boundaries become part of the text the model actually reads.
How message roles reach the model
Message roles reach the model as formatting tokens inserted by the chat template, not as metadata stored outside the text. A decoder-only model sees one sequence of tokens. The template wraps every message in markers such as a role header and an end-of-turn token, then appends an open assistant header so that the model knows it should generate the next assistant turn.
The model learns what each role means during instruction tuning and preference training. Training data pairs system and user turns with high-quality assistant turns, and the loss is usually computed only on assistant tokens. As a result, the model learns to treat user text as a request, system text as standing guidance and its own role as the voice that answers.
The following table shows the processing steps from an API request to generated text.
| Step | What happens | Responsible component |
|---|---|---|
| Request assembly | Application builds a list of role-tagged messages | Client code |
| Template rendering | Messages are wrapped in role headers and delimiters | Chat template |
| Tokenization | Rendered text becomes token IDs, including special tokens | Tokenizer |
| Generation | Model continues after the open assistant header | Language model |
| Parsing | Output is split at the end-of-turn or stop token | Serving layer |
The standard roles and their purpose
Most chat interfaces share a core set of four roles, although names vary between providers. Some APIs call the system role developer, and some treat tool output as a special user message. The underlying idea is the same: each role defines who authored the text and how the model should weigh it.
| Role | Typical author | Purpose | Usual position |
|---|---|---|---|
| System | Application developer | Sets persona, rules, format and constraints | First message |
| User | End user | Asks questions or gives tasks | Alternates with assistant |
| Assistant | The model | Holds prior model replies and tool calls | After each user or tool turn |
| Tool | External function or API | Returns results of a requested call | After an assistant tool call |
The assistant role has a second use besides storing history. A developer can insert an assistant message the model never wrote, a technique called prefilling, to steer the start of the next answer. Some APIs allow a partial final assistant message, which the model then continues token by token.
The tool role supports function calling and agent loops. The assistant emits a structured call, the application executes it and returns the result under the tool role, often linked by a call identifier. Keeping tool output in its own role helps the model distinguish retrieved data from instructions.
Roles and the instruction hierarchy
Message roles form the basis of an instruction hierarchy, an ordering of trust in which higher roles override lower ones when instructions conflict. Providers train models so that system instructions outrank user requests, and user requests outrank content that arrives through tools or documents.
This hierarchy is a learned tendency, not a hard guarantee. A model enforces it only as well as its training allows, so a persuasive user message or a malicious web page returned by a tool can still change behavior. That weakness is the core of prompt injection, in which untrusted text imitates a higher-priority instruction.
The table below compares how much authority each role normally receives and the risks attached to it.
| Role | Default trust | Main risk | Common safeguard |
|---|---|---|---|
| System | Highest | Leaked or overly long instructions | Keep secrets out of prompts |
| User | Medium | Attempts to override system rules | Refusal training and policy checks |
| Tool | Lowest | Indirect prompt injection | Treat output as data, filter content |
| Assistant history | Treated as own words | Fabricated history inserted by clients | Validate stored conversation state |
How roles relate to prompts and templates
Message roles sit between the abstract idea of a prompt and the concrete chat template. A system prompt is simply the content of the system role; a multi-turn conversation is a sequence of user and assistant roles. The template is the model-specific serialization that makes those roles visible to the network.
Because templates differ between model families, sending the wrong template can degrade output sharply. A base model, which never saw role tokens in training, has no learned meaning for roles and simply continues text. Role labels therefore matter only for models that were instruction-tuned with that format.
| Concept | Level | Relation to roles |
|---|---|---|
| Prompt | Content | Text placed inside one or more roles |
| System prompt | Content | The content of the system role |
| Chat template | Serialization | Turns role lists into token sequences |
| Special tokens | Vocabulary | Mark role boundaries and turn ends |
| Multi-turn conversation | Structure | An ordered history of alternating roles |
Common mistakes when using message roles
Most problems with message roles come from misplaced content or broken ordering. Several mistakes recur in production systems:
- Placing untrusted documents in the system role, which grants them the highest authority.
- Putting standing rules in a user turn, where later user messages can dilute or override them.
- Breaking strict alternation on templates that require user and assistant to alternate.
- Dropping tool call identifiers, so the model cannot match results to calls.
- Assuming roles provide security isolation; they shape behavior but do not enforce access control.
A sound practice is to keep rules in the system role, the current request in the user role and every external text in tool or clearly delimited user content. Long histories also consume the context window, so older turns are often summarized or trimmed.
Understanding it simply
Think of a chat with an AI model as a script for a play. Each line has a name in front of it. The name tells the model who is talking. The system line is the director giving instructions. The user line is the audience member asking a question. The assistant line is the model itself. The tool line is a helper bringing back facts.
These names help the model keep the conversation straight. The key point is that roles tell the model whose words to trust most. The director usually wins over the audience. Still, the system is not perfect, and clever text can sometimes confuse it.
Applied in practice
A software team builds a customer support assistant for an online retailer. The system role states the tone, the return policy and a rule never to promise refunds above a set limit. Each customer question goes into a user message, and order lookups run through a function whose results return in the tool role.
During testing, a customer pasted a fake note claiming to be from management that approved a full refund. Because the note arrived in the user role and the policy lived in the system role, the model followed the system rule and offered the standard process instead. The team also wrapped retrieved order notes in the tool role after finding that one note contained instruction-like text. These changes cut policy violations noticeably in their evaluation set and made the assistant’s behavior easier to audit.