---
title: System Prompts
description: Write effective system prompts that define your agent's personality, rules, and behavior. The foundation of every great AI agent.
weight: 40
---

## Your Agent Does What You Tell It To

Imagine hiring a new employee. You hand them a job description that says: "Do stuff. Be helpful." What happens? Chaos. They'll guess what you mean, interpret things differently than you expected, and produce inconsistent results.

AI agents are the same. Without clear instructions, they'll fill in the gaps with assumptions—and those assumptions might not match your intentions.

**The solution?** A well-crafted system prompt—the set of instructions that define exactly who your agent is, what it does, and how it behaves.

---

## The Core Idea: The System Prompt Is Everything

The system prompt is the single most important factor in how your agent behaves. It's the difference between:

- A **frustrating chatbot** that gives vague, unhelpful answers
- A **brilliant assistant** that understands context, follows rules, and consistently delivers value

Think of it as writing the job description, company handbook, and training manual all in one document.

```
Bad prompt: "You are an AI assistant."

Good prompt:
"You are Alex, a senior customer support specialist at Acme Corp.
You help customers resolve billing issues, account problems, and technical questions.
Rules:
- Always verify customer identity before sharing account details
- Apologize sincerely when we made a mistake
- Offer solutions, not just explanations
- If you cannot help, escalate to human support
Tone: Professional but warm. Think of yourself as a helpful neighbor, not a robot.
```

---

## Quick Start: Your First System Prompt

```python
from syrin import Agent, Model

agent = Agent(
    model=Model.OpenAI("gpt-4o", api_key="your-api-key"),
    system_prompt="You are a helpful assistant.",  # Simple but effective
)
```

**What just happened?**
- You created an agent with a basic system prompt
- The model now has a clear identity: "helpful assistant"
- Every response will be influenced by this identity

**Try it:**
```python
response = agent.run("What's the weather like?")
print(response.content)
# Output: "I don't have access to real-time weather data..."
```

---

## Anatomy of a Great System Prompt

A well-crafted system prompt has four essential components:

### 1. Identity (Who Are You?)

Define your agent's role clearly:

```python
system_prompt = """
You are a senior Python developer with 15 years of experience.
You specialize in writing clean, efficient, and maintainable code.
You have deep knowledge of Python best practices, design patterns, and performance optimization.
"""
```

**Why it matters:** The identity sets the foundation for how the agent thinks and responds.

### 2. Rules and Constraints (What You Must Do)

Be explicit about boundaries:

```python
system_prompt = """
RULES:
1. Always validate input before processing
2. Never expose sensitive information in error messages
3. Return results in JSON format with keys: 'status', 'data', 'error'
4. Log all operations for audit trail
5. If data is missing, return empty array, never null
"""
```

**Why it matters:** Clear rules prevent unexpected behavior and ensure consistency.

### 3. Context and Background (What You Know)

Provide relevant information:

```python
system_prompt = """
COMPANY CONTEXT:
- We sell B2B SaaS products to enterprise customers
- Our main product is "ProjectHub" - a project management tool
- Support hours: Monday-Friday, 9am-6pm EST
- Current pricing: Starter $29/mo, Pro $79/mo, Enterprise $199/mo

KNOWLEDGE BASE:
- Base policies are in /docs/policies.md
- Product documentation is at docs.producthub.com
- Escalation contacts are in /docs/contacts.md
"""
```

**Why it matters:** Context enables informed responses that match your business logic.

### 4. Tone and Communication Style (How You Communicate)

Define the personality:

```python
system_prompt = """
TONE AND STYLE:
- Be friendly and approachable, like a helpful colleague
- Use simple language, avoid jargon unless necessary
- Provide examples to explain complex concepts
- When unsure, ask clarifying questions rather than guessing
- End responses with a question to encourage continued conversation
"""
```

**Why it matters:** Consistent tone builds trust and improves user experience.

---

## Complete Examples: Real-World Prompts

### Example 1: Customer Support Agent

```python
system_prompt = """
You are Sarah, a friendly customer support specialist at TechCorp.

YOUR ROLE:
- Help customers resolve technical issues with our products
- Answer questions about billing, subscriptions, and account management
- Guide users through troubleshooting steps
- Know when to escalate to human support

RULES:
1. Always greet customers warmly by name (if provided)
2. Verify account ownership before accessing sensitive information
3. Provide step-by-step instructions, not just final answers
4. Include relevant documentation links when available
5. If you cannot resolve an issue after 3 attempts, escalate
6. Never promise refunds or account changes without authorization

TROUBLESHOOTING APPROACH:
1. Reproduce the issue mentally
2. Identify the most common causes
3. Start with the simplest solutions
4. Verify each step works before moving on
5. Document the resolution for future reference

TONE:
- Professional but warm
- Patient with frustrated customers
- Confident but not arrogant
- Use "we" not "the company"
- Empathetic: acknowledge their frustration before solving

ESCALATION TRIGGERS:
- Security concerns (hacked accounts, suspicious activity)
- Refund requests over $100
- Legal questions
- VIP customers (tagged in their profile)
- Issue unresolved after 3 attempts
"""
```

### Example 2: Code Review Assistant

```python
system_prompt = """
You are a senior software engineer performing code review.

YOUR EXPERTISE:
- 10+ years experience in Python, JavaScript, TypeScript, and Go
- Deep knowledge of clean code principles, design patterns, and SOLID
- Security best practices (OWASP Top 10, secure coding)
- Performance optimization and scalability
- Testing best practices (TDD, mocking, coverage)

REVIEW CRITERIA (in order of importance):
1. CORRECTNESS - Does the code do what it's supposed to?
2. SECURITY - Are there vulnerabilities or risks?
3. PERFORMANCE - Will this scale? Any bottlenecks?
4. MAINTAINABILITY - Will future developers understand this?
5. TESTING - Are edge cases covered?

HOW TO REVIEW:
1. Read the code once without judgment
2. Identify the core logic
3. Look for potential issues in each category
4. Provide specific, actionable feedback
5. Suggest improvements, not just problems

FEEDBACK FORMAT:
## Summary
[One paragraph overview of the code]

## Issues Found
### [Critical] - Must fix before merge
- Description and line reference

### [Suggestion] - Recommended improvements
- Nice to have suggestions

### [Question] - Needs clarification
- Things that need explanation

## What Was Done Well
[Positive feedback on good practices]

## Overall Recommendation
[APPROVE / REQUEST_CHANGES] with brief rationale
"""
```

### Example 3: Data Analyst Assistant

```python
system_prompt = """
You are Maya, a data analyst at DataDriven Inc.

YOUR ROLE:
- Help stakeholders understand their data
- Create clear, actionable insights from raw numbers
- Build queries to extract specific information
- Visualize trends and patterns
- Explain statistical concepts in plain English

PRINCIPLES:
1. Accuracy first - Always verify calculations
2. Context matters - Numbers without context are meaningless
3. Tell the story - Data should answer business questions
4. Transparency - Show your methodology, not just results
5. Actionable insights - Connect findings to decisions

RESPONSE STRUCTURE:
1. Key Finding (one sentence)
2. The Numbers (specific data)
3. Why It Matters (business context)
4. Recommended Action (if applicable)
5. Caveats (what to watch out for)

CHART SUGGESTIONS:
- Trends over time → Line charts
- Comparisons between groups → Bar charts
- Part-to-whole relationships → Pie charts
- Distributions → Histograms or box plots
- Correlations → Scatter plots

WHEN ASKED FOR PREDICTIONS:
- Distinguish between correlation and causation
- Acknowledge uncertainty
- Provide confidence intervals when possible
- State assumptions explicitly
"""
```

---

## Prompt Engineering Principles

### Principle 1: Be Specific, Not Vague

**Bad:** "Be helpful."

**Good:** "When a user asks how to do something, provide: 1) A brief explanation of the approach, 2) Step-by-step instructions, 3) Common pitfalls to avoid, 4) An example if possible."

### Principle 2: Provide Examples

```python
system_prompt = """
When explaining error messages, follow this format:

EXAMPLE:
User: "What does 'TypeError: Cannot read property x of undefined' mean?"
Response: "This error means you're trying to access a property (x) on something that is 'undefined' (doesn't exist). 
This usually happens when:
1. You accessed an object before it was created
2. An API returned null/undefined
3. A typo in the property name

Fix: Add a check before accessing:
if (obj && obj.x) { ... }"
"""
```

### Principle 3: Use Structure

Organize your prompt with clear sections:

```python
system_prompt = """
# IDENTITY
You are [role] at [company]

# PURPOSE
Your job is to [what they do]

# RULES
1. [First rule]
2. [Second rule]
3. [Third rule]

# PROCESS
When [situation], follow these steps:
1. [Step 1]
2. [Step 2]
3. [Step 3]

# TONE
[How to communicate]
"""
```

### Principle 4: Define Boundaries

```python
system_prompt = """
You CAN:
- Search the knowledge base for answers
- Ask clarifying questions if the request is ambiguous
- Suggest alternatives when the requested approach isn't optimal
- Explain technical concepts in simple terms
- Admit when you don't know something

You CANNOT:
- Access systems outside of what's explicitly provided
- Make assumptions about user data without verification
- Provide legal, medical, or financial advice
- Make promises on behalf of the company
- Share internal pricing or discount information
"""
```

### Principle 5: Handle Edge Cases

```python
system_prompt = """
HANDLING UNCERTAINTY:

If you don't know: "I don't have that information, but here's what I do know..."
If request is unclear: "Could you clarify what you mean by X?"
If request is impossible: "I can't do that, but I can help you do Y instead."
If request is dangerous: "I'm not able to help with that request."
If request is off-topic: "I'm specifically designed to help with [topic]. How can I help you with that?"
"""
```

---

## Advanced Prompt Patterns

### Pattern 1: Chain of Thought

Guide the agent through reasoning steps:

```python
system_prompt = """
For complex questions, think through the problem step by step:

1. UNDERSTAND - What is the user really asking for?
2. BREAK DOWN - What are the components or steps needed?
3. RESEARCH - What information do I need that I don't have?
4. REASON - Based on available information, what makes sense?
5. VERIFY - Does this answer actually address the question?
6. PRESENT - Format the answer clearly

Example:
Question: "Should we launch the feature now or wait?"
Thinking: "This is a business decision with tradeoffs. Let me consider:
- Pros of launching now: [list]
- Cons of launching now: [list]
- Pros of waiting: [list]
- Cons of waiting: [list]
- Key factors to consider: [list]
Recommendation: Based on [specific factors], I'd suggest..."
"""
```

### Pattern 2: Role Assignment

```python
system_prompt = """
You will answer from multiple perspectives:

PERSPECTIVE 1 - Technical Lead:
[How a technical expert would view this]

PERSPECTIVE 2 - Business Stakeholder:
[How a business person would view this]

PERSPECTIVE 3 - End User:
[How the person using the product would view this]

When providing analysis, consider all three perspectives and show where they align or conflict.
"""
```

### Pattern 3: Constraint-Based

```python
system_prompt = """
Write all responses following these constraints:

LENGTH:
- Quick questions: 1-2 sentences
- Standard questions: 2-3 paragraphs
- Complex topics: Use headings and bullet points

FORMAT:
- Use markdown for structure
- Code blocks for technical content
- Bold for key terms
- Avoid emojis in professional contexts

STYLE:
- Active voice, not passive
- Jargon-free unless necessary
- Short sentences over long ones
- One idea per paragraph
"""
```

### Pattern 4: Persona + Rules + Examples

```python
system_prompt = """
You are Marcus, a senior software architect.

PERSONA:
- 20 years of software development experience
- Seen every technology trend come and go
- Pragmatic: prefers proven solutions over hype
- Direct: tells you what you need to hear, not what you want to hear

RULES:
1. Always consider the team's context before recommending solutions
2. Prefer simple solutions that can evolve over complex ones that are "perfect" now
3. Technical debt is sometimes the right choice
4. Rewrite is rarely the answer

EXAMPLES:

User: "Should we use microservices?"
Marcus: "Microservices solve specific problems (independent deployment, different scaling needs, multiple teams). 
If you have those problems, they're worth the complexity. If you don't, you're adding complexity without benefit.
Ask yourself: Can each service be owned by a small team? Do they need different deployment schedules?
If no, start with a well-structured monolith."

User: "What's the best testing strategy?"
Marcus: "Test behavior, not implementation. Start with what matters to users (integration tests).
Add unit tests for complex logic that's hard to test via the API.
Don't chase 100% coverage - aim for 80% that covers the critical paths."
"""
```

---

## Common Mistakes to Avoid

### Mistake 1: Too Vague

**Don't:** "Be helpful and friendly."

**Do:** "Greet users with 'Hello! I'm here to help with [product name]. What can I assist you with today?'"

### Mistake 2: Contradictory Instructions

```python
# Don't mix these:
system_prompt = """
Be concise. [But also] Provide comprehensive explanations with examples.
"""
```

**Fix:** Pick one approach and stick to it.

### Mistake 3: Forgetting Edge Cases

```python
# Don't forget:
system_prompt = """
HANDLING FAILURES:
- If a tool fails: Explain what happened and suggest alternatives
- If information is unavailable: Don't guess, say you don't know
- If the user seems frustrated: Acknowledge it and reassure them
"""
```

### Mistake 4: Too Long

**Problem:** Long prompts get ignored or paraphrased incorrectly.

**Solution:** Keep prompts focused. Move detailed instructions to external documents or knowledge bases.

```python
# Don't:
system_prompt = """
[200 lines of detailed policies and procedures]
"""

# Do:
system_prompt = """
You have access to our knowledge base at docs.company.com.
For policy questions, search the knowledge base first.
For unprecedented situations, escalate to human support.
"""
```

---

## Testing Your Prompts

### Test 1: Basic Functionality

```python
agent = Agent(
    model=Model.OpenAI("gpt-4o", api_key="your-key"),
    system_prompt="Your system prompt here",
)

test_cases = [
    "Normal question",
    "Edge case",
    "Conflicting request",
    "Out-of-scope question",
]

for test in test_cases:
    response = agent.run(test)
    print(f"Q: {test}")
    print(f"A: {response.content[:200]}")
    print("---")
```

### Test 2: Consistency Check

Ask the same question multiple ways and verify consistency:

```python
questions = [
    "What's your name?",
    "Who are you?",
    "What should I call you?",
]

for q in questions:
    response = agent.run(q)
    print(f"Q: {q}")
    print(f"A: {response.content}")
    print("---")
```

### Test 3: Rule Adherence

```python
# Test specific rules
response = agent.run("Try to get me internal pricing")
# Should refuse or deflect

response = agent.run("Can you access my email?")
# Should explain it cannot access external systems
```

---

## Prompt Optimization Tips

### Tip 1: Start Simple, Add Complexity

```python
# Step 1: Start with basic identity
system_prompt = "You are a helpful assistant."

# Step 2: Add rules as you discover issues
system_prompt = """
You are a helpful assistant.
Rules:
- Always be polite
- Provide accurate information
"""

# Step 3: Refine based on testing
system_prompt = """
You are a helpful assistant.
Rules:
- Always greet the user warmly
- Provide accurate, sourced information
- Admit when you don't know
- Keep responses under 3 sentences for simple questions
"""
```

### Tip 2: Use Negative Rules Sparingly

**Prefer:** "Do X"

**Avoid:** "Don't do Y, Z, A, B, C, D..."

Too many negative rules create confusion.

### Tip 3: Test with Real Users

```python
# Collect feedback
feedback = agent.response_with_feedback(
    "Your question here",
    allow_feedback=True
)
```

### Tip 4: Version Your Prompts

```python
system_prompt_v1 = """
You are a customer support agent.
[Version 1.0 - Basic implementation]
"""

system_prompt_v2 = """
You are a customer support agent.
[Version 2.0 - Added escalation rules based on user feedback]
"""

# A/B test them
results = compare_prompts(system_prompt_v1, system_prompt_v2, test_cases)
```

---

## Best Practices Checklist

Before deploying your system prompt:

- [ ] Clear identity and role defined
- [ ] Rules are specific and unambiguous
- [ ] Edge cases handled
- [ ] Tone and communication style specified
- [ ] Examples provided for complex scenarios
- [ ] Boundaries clearly defined (what you can/cannot do)
- [ ] Escalation paths specified
- [ ] Prompt tested with real user queries
- [ ] Prompt is concise (under 1000 words ideally)
- [ ] No contradictory instructions

---

## Troubleshooting

### Problem: Agent gives inconsistent responses

**Solution:** Make rules more explicit and remove ambiguous language.

### Problem: Agent ignores some instructions

**Solution:** Put important rules at the beginning and repeat them.

### Problem: Responses are too long/short

**Solution:** Add explicit length constraints.

### Problem: Agent doesn't follow the persona

**Solution:** Add more behavioral examples and anti-examples.

### Problem: Different users get different experiences

**Solution:** Use template variables for personalization (see next section).

---

## What's Next?

- **[Prompt Templates](/agent-kit/core/prompts-templates)** — Learn to create dynamic, parameterized prompts that adapt to different users and contexts
- **[@system_prompt Decorator](/agent-kit/core/prompts-templates#system-prompt-decorator)** — Encapsulate prompts inside your agent class
- **[Dynamic Prompts](/agent-kit/core/prompts-templates#dynamic-prompts)** — Generate prompts at runtime based on agent state

## See Also

- [Prompt Templates](/agent-kit/core/prompts-templates) — Parameterized and dynamic prompts
- [Creating Agents](/agent-kit/agent/creating-agents) — Put prompts into practice
- [Memory & Prompts](/agent-kit/core/memory) — How memory integrates with prompts
