System, user and assistant roles in LLM chat APIs, explained simply

Every message you send to a chat model carries a role. System sets the rules, user asks, assistant answers. Here is what each one does, who writes it, and why the model's own old answers have to go back in.

Three cards. System, written by you the developer, the rules. User, written by the person, the question. Assistant, written by the model, the answer. Next to them, a JSON request body for POST /api/chat with a messages list holding one system message, one user message and one assistant message, each highlighted in its own colour.
Fig. 1 — One list of messages, three kinds of author. The role tells the model who said what.

When you chat with an AI in an app, it feels like one continuous conversation. Under the hood, the app sends the model a list of messages, and every message has a label saying who wrote it. That label is the role.

There are three roles you will use all the time: system, user and assistant. They are the same idea in Ollama, OpenAI, Anthropic and almost every chat API. Once you understand them, prompts, chatbots and agents all make more sense.

This guide explains each role with simple examples, shows a real test in Postman, and lists the mistakes beginners usually make. It is part five of a series, but it stands on its own.

The three roles in one table

Role Who writes it What it is Example
system You, the developer The rules. Who the bot is, its tone, its limits “You are a friendly tutor. Answer in two lines.”
user The person chatting The question. What they type “Explain RAG”
assistant The model The answer. Its reply, sent back as history next time “RAG looks up facts first, then answers.”

In one line: system sets the rules, user asks, assistant answers.

An analogy: a new employee at a help desk

Imagine you hire someone for your shop’s help desk.

  • On their first morning, the manager gives them a card: “You work for TechBazaar. Be polite. Only discuss our products. Never promise refunds over 10 days.” Customers never see this card. That is the system message.
  • A customer walks up and asks a question. That is a user message.
  • The employee replies. That is an assistant message.

Now imagine this employee has a strange condition: every time a customer speaks, they forget everything that was said before. To keep the conversation going, someone has to hand them a written transcript each time: the card, everything the customer said, and everything they themselves said. That is exactly how an LLM works, and it is why the assistant role exists. More on that below.

How the roles look in a real request

Here is a request to Ollama’s chat endpoint, POST http://localhost:11434/api/chat, using all three roles:

{
  "model": "qwen3.5:4b",
  "messages": [
    { "role": "system",    "content": "You are a friendly tutor. Answer in two lines." },
    { "role": "user",      "content": "Explain RAG" },
    { "role": "assistant", "content": "RAG looks up facts first, then answers using them." },
    { "role": "user",      "content": "Give me a real-world example." }
  ],
  "think": false,
  "stream": false
}

The model reads the whole list from top to bottom, then writes the next assistant message. Here, it knows the rules (two lines, friendly), it knows what was already explained, and it knows “example” means “an example of RAG”, because the earlier messages are right there.

The system role: the rules

The system message is written by you, the developer, once, at the top of the list. The person chatting never sees it. Use it for:

  • Identity: “You are the support assistant for TechBazaar.”
  • Tone and style: “Be friendly. Use simple English. Keep answers under 100 words.”
  • Limits: “Only answer questions about our products. If you don’t know, say so.”
  • Output format: “Reply with JSON containing explanation and metaphor.”

See the difference in Postman

The quickest way to see what a system message does is to send the same question twice in Postman: once without a system message, once with one. Postman shows the request and the JSON response neatly formatted side by side, which makes it much easier to read than a terminal. (The REST API guide walks through these exact two requests in Postman, with screenshots.)

First, only a user message. We ask “Explain AI in two sentences.”

{
  "model": "qwen3.5:4b",
  "messages": [
    { "role": "user", "content": "Explain AI in two sentences." }
  ],
  "think": false,
  "stream": false
}

The reply (trimmed to the important part):

"message": {
  "role": "assistant",
  "content": "AI is a branch of computer science that aims to create systems capable of performing tasks that typically require human intelligence, such as reasoning, learning, and problem-solving. By processing vast amounts of data, these intelligent algorithms can recognize patterns, make predictions, and adapt to new situations with minimal human intervention."
}

We get a correct, plain, textbook answer. Nothing told the model how to behave, so it used its defaults.

Now add a system message. Same question, but first we tell the model who it is and how to reply:

{
  "model": "qwen3.5:4b",
  "messages": [
    {
      "role": "system",
      "content": "You are AI Explainer who can explain any complex topic with a metaphore. Reply with STRICT JSON"
    },
    { "role": "user", "content": "Explain AI in two sentences." }
  ],
  "think": false,
  "stream": false
}

The reply:

"message": {
  "role": "assistant",
  "content": "{\n  \"explanation\": \"Imagine an AI as a student who has read every book ever written; instead of memorizing, it instantly recognizes patterns to solve puzzles you haven't even asked about yet.\",\n  \"metaphor\": \"A library's omniscient reader that never stops studying.\"\n}"
}

Same model, same question, very different answer. Now the reply is JSON with an explanation and a metaphor: “Imagine an AI as a student who has read every book ever written…” The user didn’t ask for any of that. The system message did.

That is the power of the system role: you shape every answer without the user having to ask.

The user role: the question

The user message is whatever the person types. In a chat app, every time someone presses Enter, your code adds one new user message to the list.

Treat user messages as input you don’t control. People will ask off-topic questions, paste long text, or even type “ignore your instructions”. Your system message and your code should be ready for that. (More on this under common mistakes.)

The assistant role: the answer, and the memory

The model’s replies come back with the role assistant:

"message": {
  "role": "assistant",
  "content": "RAG looks up facts first, then answers using them."
}

So why would you ever send an assistant message? Because the model has no memory between requests.

Every request starts with an empty slate. If you send only the new question, the model has no idea what it said a moment ago. To continue a conversation, your app keeps a list of messages, and after each reply it adds the model’s answer as an assistant message, then sends the whole list next time.

Without the assistant messages, the model would see a series of questions with no answers, and follow-ups like “give me an example of that” would make no sense. With them, it sees the full conversation and can carry on naturally.

“The model doesn’t remember. Your app does, by sending the assistant’s old answers back.”

This “model has no memory” idea is called being stateless, and it is important enough to have a full walk-through, with working code, in the Python and Java guides.

A bonus use: teaching by example

Because the model trusts the conversation it is given, you can also write fake earlier turns to show it the style you want. This is called few-shot prompting:

"messages": [
  { "role": "system",    "content": "Turn product names into short slugs." },
  { "role": "user",      "content": "Wireless Noise Cancelling Headphones" },
  { "role": "assistant", "content": "wireless-nc-headphones" },
  { "role": "user",      "content": "Stainless Steel Water Bottle 1L" }
]

The model sees one finished example and copies the pattern for the new one.

What about /api/generate?

Ollama’s simpler endpoint, /api/generate, takes a single prompt instead of a list of messages. It has no user or assistant roles, but it does accept a system field for the same purpose as the system role:

{
  "model": "qwen3.5:4b",
  "system": "You are a friendly tutor. Answer in two lines.",
  "prompt": "Explain RAG",
  "stream": false
}

For anything with a back-and-forth, use /api/chat with roles. The REST API guide compares the two.

Common mistakes with roles

  1. Putting the rules in every user message. “Answer in JSON. Question: …” repeated each time. Put rules in one system message at the top instead.
  2. Forgetting to add the assistant’s reply to the history. The bot then “forgets” its own answers. Always append the reply after each request.
  3. Letting users write the system message. The system message is your control panel. Never paste user input into it.
  4. Trusting the system prompt as security. A system message strongly guides the model, but a determined user can sometimes talk it out of the rules. Enforce anything important (permissions, refunds, prices) in your code, not only in the prompt.
  5. Expecting “STRICT JSON” to always be valid JSON. Asking in the system message usually works, but small models can slip. Ollama also has a "format": "json" option (or a JSON schema) that constrains the output; use it when your code must parse the reply.

One more role you will meet later

When a model can call functions (search the web, look up an order, read a file), the result of that function goes back to the model as a message with the role tool. That is how AI agents work, and it builds directly on the three roles here.

Key takeaways

  • system = the rules, written by you, once, at the top. The user never sees it.
  • user = the question, written by the person. Treat it as untrusted input.
  • assistant = the model’s answer. Send it back as history, because the model is stateless.
  • The model reads the whole list and writes the next assistant message.
  • Enforce important rules in code; use format when you need guaranteed JSON.

The full series: Run LLMs locally with Ollama

Each part stands on its own, so jump to whichever you need:

  1. How to run an LLM on your own computer
  2. What is Ollama? The video player for AI models, and localhost:11434 explained
  3. Ollama CLI commands: the complete cheat sheet
  4. The Ollama desktop app: chat, pick models, and launch Claude Code or Copilot
  5. System, user and assistant roles explained (you are here)
  6. Ollama REST API: /api/generate vs /api/chat
  7. Call a local LLM from Python: a stateless request, then a chatbot with memory
  8. Call a local LLM from Java: HttpClient, a stateless request, then a chatbot with memory

See it in action

Prefer watching? This video walks through the same ideas with live, hands-on demos.

Video thumbnail: System, user and assistant roles in LLM chat APIs, explained simplyWatch on YouTube ↗

Comments

LEAVE A COMMENT
No sign-up. Comments appear after a quick review.