Session 1· H3· 15 min
Prompt Roles — system vs user messages
What you'll learn
- ▸Distinguish system instructions from user input
- ▸Use a system role to control tone and output format
- ▸See how the same user question changes with a different system message
What you will build
A script that takes a topic on the command line and asks the same question under two personalities: "strict exam tutor" and "chill friend explaining over coffee". You will watch how the system message reshapes the reply without touching the user question.
The three roles in every chat API
system
you, the developer
- •Sets persona, rules, tone, format
- •Invisible to the end user
- •Weighed heavily by the model
- •Reuse across many user questions
user
the human asking
- •The actual question or task
- •Short, varied, unpredictable
- •What your chatbot interface collects
assistant
the model replying
- •Previous replies when simulating memory
- •You only include these when replaying history
- •Session 1 H5 shows how to use this
The code
src/03_prompt_roles.py (excerpt)
response = client.responses.create(
model=model,
input=[ ①
{"role": "system",
"content": "You are a strict exam tutor. Use short bullets."}, ②
{"role": "user",
"content": f"Explain {args.topic} to me."}, ③
],
)
print(response.output_text)①Instead of a plain string, input is a LIST of messages.
②The system message tells the model HOW to answer — persona + format rules.
③The user message is the actual topic. f"..." is an f-string that injects args.topic.
Run it
$ python src/03_prompt_roles.py --topic "time management"
The magic trick
Change JUST the system message text and rerun. Same question, completely different answer style. Put all your persona/format/rules in the system message, never in the user message.
Knowledge check
Knowledge Check
Where should you put the rule "always answer in JSON"?
Code Check
What data type is the "input" parameter when you use roles?
Recap — what you just learned
- ✓Chat APIs take a LIST of messages, each tagged with a role
- ✓system = persona and rules, user = the question, assistant = prior replies
- ✓The system message is the most powerful prompting lever — use it for format, tone, persona