System, User, and Assistant Message Roles
What you'll learn: How to structure conversation messages with the correct roles to control AI behavior and context.
The Three-Role Structure
When you send a request to a chat completion API, you don't just send raw text — you send a conversation made up of messages. Each message has a role that tells the model how to interpret it:
- System: Instructions that set the AI's behavior, personality, or constraints
- User: The human's input or question
- Assistant: The AI's previous responses (used in multi-turn conversations)
Think of it like a play: the system message is the stage directions, the user is one character speaking, and the assistant is another character responding.
Why Roles Matter
The model treats each role differently:
- System messages establish the "rules of the game" — they're like setting the temperature on your oven before cooking. Examples: "You are a helpful coding tutor" or "Respond only in JSON format."
- User messages are the actual queries or prompts you want answered
- Assistant messages help maintain conversation history, so the model remembers what it said before
System Prompts: Your Control Panel
The system message is your most powerful tool for steering behavior. It's processed first and influences every response. Use it to:
- Define the assistant's role or expertise
- Set output formatting requirements
- Establish boundaries or constraints
- Provide context that applies to all interactions
Key Takeaway: Messages aren't just text — their role determines how the model interprets them, with system messages acting as persistent instructions that shape all responses.