Lesson 4 / 29

System, User and Assistant Messages

Use the message roles of chat APIs correctly.

Standing rules versus the current request

Chat-style APIs take a list of messages with roles. The system message sets durable behaviour: persona, rules, format, safety limits. User messages carry the request and data. Assistant messages are the model's earlier replies (and can be pre-filled to demonstrate a style). Put stable instructions in the system message and variable content in user messages. Remember that the model does not have a hidden memory: each call must include whatever earlier turns it needs. Never put secrets in prompts, and do not assume the system prompt can be kept confidential from a determined user.

A messages array

The shape used by most chat APIs; exact field names vary by provider. Illustrative; not run here.

[
  {"role": "system", "content": "You are a concise support assistant. Answer in at most 3 sentences."},
  {"role": "user", "content": "How do I reset my password?"},
  {"role": "assistant", "content": "Open Settings > Security and choose Reset password."},
  {"role": "user", "content": "And if I no longer have access to my email?"}
]

Rebuild history each call

Because the model keeps no memory, send the earlier turns you still need with every request and drop what you do not.

Quick check: Where should stable rules and persona go?

  • Only in the last user message
  • In the system message
  • In a comment
  • Nowhere
Answer

In the system message — The system message carries instructions that apply to the whole conversation.