All your prompts so far have been user messages. There's another role: system. The system prompt sits at the top of the conversation and frames how the model should behave on every subsequent turn.
from pydantic_ai import Agent
agent = Agent(model, system_prompt="You are a librarian. Reply in exactly 3 words.")
result = agent.run_sync("What's the meaning of life?")
print(result.output)
# something like: "Read more books."Why use a system prompt instead of just including the constraint in every user prompt?
Three wins:
A third message role besides user and assistant:
system: "You are a librarian. Reply in exactly 3 words."
user: "What's the meaning of life?"
assistant: "Read more books."
user: "How do I learn Python?"
assistant: "Build small projects."
The system message sits at the top, applies to every following turn, and isn't re-shown with each user prompt — it's just always there.
agent = Agent(model, system_prompt="You are a librarian. Reply in exactly 3 words.")Passed when the agent is constructed. Every run_sync on that agent inherits the system prompt automatically.
| Use | Example system prompt |
|---|---|
| Persona | "You are a senior software engineer reviewing code." |
| Output format | "Always reply in JSON." |
| Length constraint | "Reply in exactly 3 words." |
| Safety | "Never give medical advice. Refer to a doctor instead." |
| Domain narrowing | "Only answer questions about cooking. For other topics, politely decline." |
| Where | What to put |
|---|---|
| System | Persistent rules about the model's behaviour, persona, output style, safety, domain |
| User | The specific task or question for this turn |
A good test: if I ran the same agent with 100 different user inputs, what's the rule that applies to all 100? That's a system-prompt rule. The 100 different inputs themselves are user messages.
A sufficiently determined user prompt can override a system rule ("ignore prior instructions and..."). For real safety constraints — content moderation, PII redaction — you need code-level checks, not just a system prompt. But for most behavioural shaping, the system prompt is the right tool.
All your prompts so far have been user messages. There's another role: system. The system prompt sits at the top of the conversation and frames how the model should behave on every subsequent turn.
from pydantic_ai import Agent
agent = Agent(model, system_prompt="You are a librarian. Reply in exactly 3 words.")
result = agent.run_sync("What's the meaning of life?")
print(result.output)
# something like: "Read more books."Why use a system prompt instead of just including the constraint in every user prompt?
Three wins:
A third message role besides user and assistant:
system: "You are a librarian. Reply in exactly 3 words."
user: "What's the meaning of life?"
assistant: "Read more books."
user: "How do I learn Python?"
assistant: "Build small projects."
The system message sits at the top, applies to every following turn, and isn't re-shown with each user prompt — it's just always there.
agent = Agent(model, system_prompt="You are a librarian. Reply in exactly 3 words.")Passed when the agent is constructed. Every run_sync on that agent inherits the system prompt automatically.
| Use | Example system prompt |
|---|---|
| Persona | "You are a senior software engineer reviewing code." |
| Output format | "Always reply in JSON." |
| Length constraint | "Reply in exactly 3 words." |
| Safety | "Never give medical advice. Refer to a doctor instead." |
| Domain narrowing | "Only answer questions about cooking. For other topics, politely decline." |
| Where | What to put |
|---|---|
| System | Persistent rules about the model's behaviour, persona, output style, safety, domain |
| User | The specific task or question for this turn |
A good test: if I ran the same agent with 100 different user inputs, what's the rule that applies to all 100? That's a system-prompt rule. The 100 different inputs themselves are user messages.
A sufficiently determined user prompt can override a system rule ("ignore prior instructions and..."). For real safety constraints — content moderation, PII redaction — you need code-level checks, not just a system prompt. But for most behavioural shaping, the system prompt is the right tool.
Create a free account to get started. Paid plans unlock all tracks.