Message roles

Also known as: chat roles · message role

On this page 7

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.

StepWhat happensResponsible component
Request assemblyApplication builds a list of role-tagged messagesClient code
Template renderingMessages are wrapped in role headers and delimitersChat template
TokenizationRendered text becomes token IDs, including special tokensTokenizer
GenerationModel continues after the open assistant headerLanguage model
ParsingOutput is split at the end-of-turn or stop tokenServing layer
From role-tagged request to model output

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.

RoleTypical authorPurposeUsual position
SystemApplication developerSets persona, rules, format and constraintsFirst message
UserEnd userAsks questions or gives tasksAlternates with assistant
AssistantThe modelHolds prior model replies and tool callsAfter each user or tool turn
ToolExternal function or APIReturns results of a requested callAfter an assistant tool call
Common message roles in chat models

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.

RoleDefault trustMain riskCommon safeguard
SystemHighestLeaked or overly long instructionsKeep secrets out of prompts
UserMediumAttempts to override system rulesRefusal training and policy checks
ToolLowestIndirect prompt injectionTreat output as data, filter content
Assistant historyTreated as own wordsFabricated history inserted by clientsValidate stored conversation state
Trust levels by role

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.

ConceptLevelRelation to roles
PromptContentText placed inside one or more roles
System promptContentThe content of the system role
Chat templateSerializationTurns role lists into token sequences
Special tokensVocabularyMark role boundaries and turn ends
Multi-turn conversationStructureAn ordered history of alternating roles
Message roles compared with related concepts

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.