What are the three message roles in a chat style LLM prompt and what does each represent?
system carries standing orders, user carries the current turn's input, and assistant replays prior model responses so the next call has context.
Imagine a new employee at a help desk. Before the shift the manager hands them a short briefing: who they work for, what tone to use, what they must never say. That briefing is the system message. During the shift, customers walk up and ask questions; each question is a user message. The employee writes their previous answers on a notepad and keeps referring to it, so the conversation feels continuous. Those notes are the assistant messages. Every new question, the employee re-reads the briefing, the conversation so far, and the new question, then replies.
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.
Every chat style LLM API is built on the same three core roles: system, user, assistant. The labels look almost trivial, but the placement decisions they force are where a lot of production prompt-engineering quality lives.
What each role carries
The system message is the model's standing orders for the call. It holds persona, tone, output format, refusal behavior, schema, tool descriptions and jurisdiction-specific rules: anything that should hold true across every turn of the conversation. By convention it is set once per session and reused.
The user message is the dynamic surface. In a chatbot it is whatever the human typed; in a backend pipeline it is whatever your application is asking. Retrieved RAG context typically belongs here too, alongside the query that needs it. Long documents go above the query, with the query at the end of the prompt.
The assistant message is the model's earlier replies replayed back to it. A stateless API such as Chat Completions does not remember anything across calls, so your code stores the prior responses and resends them as assistant turns on every new request. Without this, multi-turn coherence collapses.
Two further roles sit beside these three. A tool role (or a tool-result block on Anthropic) carries the output of a tool call back to the model. With OpenAI's o1 and newer models, a developer message takes the place of the system message and is prioritized ahead of user messages.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
Real products, models, and research that use this idea.
- OpenAI's Chat Completions API accepts system, user, assistant and tool messages. With o1 and newer models, a developer message replaces the system message, and the Responses API also takes top-level instructions.
- Anthropic's Messages API has explicit user/assistant turns plus a top-level system parameter; marking the system block with cache_control lets prompt caching reuse it on repeated calls.
What an interviewer would ask next. Try answering before peeking at the approach.
QIf the API is stateless, how do production chatbots get long-conversation memory without blowing the context window?
Sliding window of recent turns plus a running summary in system or a dedicated summary message. Mention vector store recall for older turns when truly long-horizon.
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.
Putting the user's per-turn question into the system message; the system role is for persistent rules, not the current query.
60 second bullets to scan on the way to the call.
The three role labels and one-sentence purpose of each
Which chat APIs are stateless and what that means for transcripts
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.