Bird
Raised Fist0
Prompt Engineering / GenAIml~6 mins

Message roles (system, user, assistant) in Prompt Engineering / GenAI - Full Explanation

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Introduction
When people interact with AI chat systems, the system needs to understand who is saying what. This helps the AI respond correctly and keep the conversation clear. Different roles in messages help organize the flow between the AI, the user, and the system itself.
Explanation
System Role
The system role sets the overall instructions or context for the AI. It guides how the AI should behave during the conversation, like setting the tone or rules. This role is not part of the conversation itself but shapes how the assistant responds.
The system role controls the AI's behavior and sets the conversation context.
User Role
The user role represents the person talking to the AI. Messages from the user are questions, commands, or statements that the AI needs to understand and respond to. This role drives the conversation forward by providing input.
The user role is the source of input that the AI responds to.
Assistant Role
The assistant role is the AI itself replying to the user. It generates answers, suggestions, or any output based on the user's messages and the system's instructions. This role completes the conversation loop by providing helpful responses.
The assistant role delivers the AI's responses to the user.
Real World Analogy

Imagine a play where the director gives instructions, the actor listens and acts, and the audience asks questions. The director sets the scene, the audience drives the story with questions, and the actor responds accordingly.

System Role → The director who sets the rules and tone for the play
User Role → The audience member asking questions or making requests
Assistant Role → The actor who responds and acts based on the director's instructions and audience input
Diagram
Diagram
┌─────────────┐      ┌─────────────┐      ┌──────────────┐
│   System    │─────▶│  Assistant  │◀─────│    User      │
│  (Director) │      │  (Actor)    │      │ (Audience)   │
└─────────────┘      └─────────────┘      └──────────────┘
Diagram showing the system directing the assistant, who responds to the user.
Key Facts
System RoleProvides instructions and context to guide the AI's behavior.
User RoleRepresents the person interacting with the AI by sending messages.
Assistant RoleThe AI that generates responses based on user input and system instructions.
Common Confusions
Thinking the system role is a participant in the conversation like the user or assistant.
Thinking the system role is a participant in the conversation like the user or assistant. The system role only sets the rules and context; it does not send conversational messages.
Believing the assistant role can initiate conversation without user input.
Believing the assistant role can initiate conversation without user input. The assistant responds to user messages and system instructions but does not start the conversation.
Summary
Message roles organize who says what in AI conversations to keep interactions clear.
The system role sets the AI's behavior and context but does not chat directly.
The user sends messages, and the assistant replies based on those messages and system guidance.

Practice

(1/5)
1. What is the main purpose of the system role in AI chat messages?
easy
A. To store conversation history
B. To provide user input or questions
C. To set instructions and guide the AI's behavior
D. To display the AI's answers

Solution

  1. Step 1: Understand the roles in AI chat

    The system role is designed to give the AI instructions or context on how to respond.
  2. Step 2: Differentiate from other roles

    The user role is for input, and the assistant role is for AI output, so setting instructions fits the system role.
  3. Final Answer:

    To set instructions and guide the AI's behavior -> Option C
  4. Quick Check:

    System role = instructions [OK]
Hint: System role sets AI instructions, user inputs, assistant replies [OK]
Common Mistakes:
  • Confusing system role with user input
  • Thinking assistant role sets instructions
  • Assuming system role stores chat history
2. Which of the following is the correct way to represent a user message in a chat API call?
easy
A. {"role": "assistant", "content": "Hello!"}
B. {"role": "user", "content": "What is AI?"}
C. {"role": "system", "content": "You are helpful."}
D. {"role": "bot", "content": "I can help."}

Solution

  1. Step 1: Identify the role for user input

    The user messages must have the role set to "user" to indicate input from the person.
  2. Step 2: Check each option's role field

    {"role": "user", "content": "What is AI?"} uses "user" correctly, while others use "assistant", "system", or invalid "bot".
  3. Final Answer:

    {"role": "user", "content": "What is AI?"} -> Option B
  4. Quick Check:

    User role = "user" [OK]
Hint: User messages always have role "user" in JSON [OK]
Common Mistakes:
  • Using "bot" instead of "assistant" or "user"
  • Mixing system role with user messages
  • Forgetting to set the role field
3. Given this message list sent to an AI model:
[{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Hello!"}]

What role will the AI use to respond?
medium
A. system
B. user
C. moderator
D. assistant

Solution

  1. Step 1: Understand message roles in conversation

    The AI responds with messages having the role "assistant" to show its output.
  2. Step 2: Identify the role for AI replies

    Since the input messages include system and user roles, the AI's reply will be labeled as "assistant".
  3. Final Answer:

    assistant -> Option D
  4. Quick Check:

    AI replies use role "assistant" [OK]
Hint: AI responses always have role "assistant" [OK]
Common Mistakes:
  • Thinking AI replies use "system" role
  • Confusing user input role with AI output
  • Assuming unknown roles like "moderator"
4. You wrote this message list for an AI chat:
[{"role": "system", "content": "Be concise."}, {"role": "user", "content": "Explain AI."}, {"role": "user", "content": "Tell me more."}]

Why might the AI ignore the second user message?
medium
A. Because there are two user messages without an assistant reply in between
B. Because the system role is missing
C. Because the assistant role is used twice
D. Because the user messages are empty

Solution

  1. Step 1: Check message sequence rules

    AI expects alternating user and assistant messages; two user messages in a row can cause confusion.
  2. Step 2: Identify the problem in the message list

    Here, two user messages come one after another without an assistant reply, so the AI may ignore the second user message.
  3. Final Answer:

    Because there are two user messages without an assistant reply in between -> Option A
  4. Quick Check:

    Messages alternate user-assistant-user [OK]
Hint: User and assistant messages must alternate to avoid ignored inputs [OK]
Common Mistakes:
  • Thinking system role is missing
  • Assuming assistant role used twice
  • Believing empty messages cause ignoring
5. You want the AI to act as a friendly tutor and answer questions clearly. Which message list correctly sets this up before the user asks a question?
hard
A. [{"role": "system", "content": "You are a friendly tutor. Answer clearly."}, {"role": "user", "content": "Explain math."}]
B. [{"role": "user", "content": "Explain math."}, {"role": "system", "content": "Be friendly and clear."}]
C. [{"role": "assistant", "content": "I will be friendly."}, {"role": "user", "content": "Explain math."}]
D. [{"role": "user", "content": "Explain math."}, {"role": "assistant", "content": "I will be friendly."}]

Solution

  1. Step 1: Place instructions in the system role

    Instructions for AI behavior must be in the system message before user input.
  2. Step 2: Check message order and roles

    [{"role": "system", "content": "You are a friendly tutor. Answer clearly."}, {"role": "user", "content": "Explain math."}] correctly puts the system message first with instructions, then the user question.
  3. Final Answer:

    [{"role": "system", "content": "You are a friendly tutor. Answer clearly."}, {"role": "user", "content": "Explain math."}] -> Option A
  4. Quick Check:

    System message first with instructions [OK]
Hint: Put AI instructions in system role before user messages [OK]
Common Mistakes:
  • Putting system message after user input
  • Using assistant role for instructions
  • Starting with user message without system context