# Message Roles

> The Message Roles define who authored each message in a conversation with a language model: system, user or assistant.

## What are system, user and assistant roles in an LLM chat?

The roles that mark each message in a chat request: 'system' for instructions, 'user' for user input and 'assistant' for model replies, plus tool results. The model treats them differently, so instructions and data should be separated.

- Topic: Prompting
- Type: concept

## Example

Wrong:

```js
const messages = [
  { role: 'user', content: `Rules: answer in French.\nUser: ${input}\nBot: ${lastReply}` },
];
```

Right:

```js
const messages = [
  { role: 'system', content: 'Answer in French.' },
  { role: 'user', content: previousQuestion },
  { role: 'assistant', content: lastReply },
  { role: 'user', content: input },
];
```

Separate roles keep developer rules, user text and past replies apart, so the model knows who said what.

## Common mistakes

- Pasting the whole chat history into one user message, so the model loses who said what.

## Key points

- Instructions from the developer go in the 'system' message, not mixed into user text.
- User input and retrieved text are never placed in the 'system' role.
- Messages alternate correctly and earlier 'assistant' replies are sent back as 'assistant', not as 'user'.

## Interview questions

### Why keep instructions in the system message?

Models are trained to weigh system instructions above user text, and keeping them apart makes injection harder. Some APIs take it as a separate parameter.

### Can I write assistant messages myself?

Yes. Many APIs accept 'assistant' messages you write, for example to replay history or show examples. Keep untrusted input in 'user' messages.

### What is the tool role in chat messages?

Some APIs use a 'tool' role or a tool result block to return function results to the model, linked to the call by an id.

## Related cards

- [System Prompt](https://wonderium.dev/ai/system-prompt.md)
- [LLM API](https://wonderium.dev/ai/llm-api.md)
- [Prompt Injection](https://wonderium.dev/ai/prompt-injection.md)
- [Context Window](https://wonderium.dev/ai/context-window.md)

---

- Level: [Artificial Intelligence](https://wonderium.dev/ai.md)
- HTML version: https://wonderium.dev/ai/message-roles
- Last updated: 2026-11-25
