System vs User Role Distinction
How system and user messages differ in model behavior and priority.
Two Roles, Two Purposes
Modern LLM APIs expose two primary message roles: system and user. Understanding the distinction is foundational to building well-behaved AI applications.
- System message: Written by the developer. Defines how the model behaves, what persona it adopts, what rules it follows.
- User message: The runtime input — from the end user or from an automated process.
This separation allows developers to lock in behavior without exposing control logic to users.
System Message = Developer-Defined Behavior
The system message is where you define the model's identity, rules, and constraints. It is set once (per session or per call) and persists across all turns of a conversation.
import anthropic
client = anthropic.Anthropic(api_key='YOUR_API_KEY')
response = client.messages.create(
model='claude-opus-4-5',
max_tokens=500,
system='You are a customer support agent for TechCorp. '
'Only answer questions about TechCorp products. '
'Never discuss competitor products. '
'Always be professional and concise.',
messages=[
{'role': 'user', 'content': 'What is your best laptop?'}
]
)
print(response.content[0].text)All lessons in this course
- System vs User Role Distinction
- Injecting Persistent Behaviors
- Persona and Role Definition
- Testing System Prompt Effectiveness