Tutorials10 min read25 May 2026

How to Write a System Prompt

System prompts are the single highest-leverage place to improve your AI results. Learn what goes into one, see three complete worked examples, and avoid the mistakes that make most system prompts useless.

A system prompt is the first thing an AI model sees before any conversation starts. It sets the rules, the persona, the scope, and the expected output format. If your AI tool keeps producing the wrong tone, going off-topic, or formatting things incorrectly, the fix is almost always in the system prompt.

What a System Prompt Is

When you call an AI API like Claude or OpenAI, you send an array of messages. Each message has a role. The "system" role is special — it is not part of the conversation and the user never sees it. It is the instruction layer that sits above everything.

API message structure (Python)
import anthropic

client = anthropic.Anthropic()

response = client.messages.create(
    model="claude-opus-4-5",
    max_tokens=1024,
    system="You are a helpful assistant who always responds in bullet points.",  # system prompt
    messages=[
        {"role": "user", "content": "What are the benefits of TypeScript?"}  # user message
    ]
)

In a chat product like Claude.ai, you cannot set a system prompt directly — but when you are building your own AI-powered product, the system prompt is the main lever you have for controlling behaviour.

System prompts persist across the entire conversation. They apply to every user message. This makes them more powerful — and more dangerous — than regular messages. A badly written system prompt will corrupt every response.

Why System Prompts Matter

The same user message produces radically different results depending on the system prompt. Here is the same question with two different system prompts:

System Prompt — Before
You are a helpful assistant.
User message
"How do I improve the performance of my React app?"
Response — Before (generic)
There are several ways to improve React performance:

1. Use React.memo to prevent unnecessary re-renders
2. Implement code splitting
3. Optimize images
...
(generic list with 8 items, none specific to the user's situation)
System Prompt — After
You are a senior React developer reviewing code for a production app.
When asked about performance, always:
1. Ask one clarifying question first to understand the specific bottleneck
2. Recommend profiling before optimising
3. Give concrete, measurable advice
4. Focus on the 20% of changes that produce 80% of the gain
Keep responses under 300 words unless the user asks for more detail.
Response — After (targeted)
Before I give advice: have you profiled the app yet? The React DevTools Profiler
will show you exactly which components are re-rendering and how long they take.
Optimising without profiling usually means fixing the wrong thing.

If you have profiled it — paste the slowest component and I'll look at the specific cause.

If you haven't profiled yet, that's step one. It takes 5 minutes and will tell you
more than any generic list I could give you.
The "After" response is better because it asks the right clarifying question instead of producing a generic list. That behaviour came entirely from the system prompt, not from the model.

The 5 Ingredients of a Good System Prompt

A complete system prompt covers five areas. Not all are required for every use case — but each one you leave out is a gap the model will fill with its defaults, which may not match what you want.

1. Role

Tell the model who it is. This is not just cosmetic — the role calibrates the vocabulary, depth, and assumed knowledge level of every response.

Role examples
# Generic (weak)
"You are a helpful assistant."

# Specific (strong)
"You are a senior software engineer specialising in backend systems.
You have deep expertise in distributed systems, PostgreSQL, and Node.js.
You speak to engineers at a peer level and skip basic explanations."

# Another strong example
"You are a technical writing expert who makes complex documentation
easy to understand for developers who are new to the topic."

2. Context

Give the model the background it needs to answer well. What is the product? Who is the user? What does the model need to know about the situation?

Context block
You are a support agent for Acme SaaS, a project management tool.

Context about Acme:
- Acme is used by software teams of 5–50 people
- Core features: task boards, sprint planning, GitHub integration
- Users are typically technical (developers, engineering managers)
- The product is a web app; there is no mobile app yet
- Pricing: Free (up to 5 users), Team ($15/user/month), Enterprise (custom)

3. Task Scope

Define what the model should and should not do. Explicit boundaries prevent the model from wandering into territory you did not intend.

Task scope examples
# What it should do:
- Answer questions about Acme's features and pricing
- Help users troubleshoot common issues using the knowledge base
- Escalate to a human agent when the issue is billing-related or a bug

# What it should NOT do:
- Make up features that don't exist
- Answer questions unrelated to Acme (no general tech support)
- Make promises about roadmap items or future releases
- Discuss competitors

4. Constraints

Set the behavioural rules: tone, length, things to always do, things to never do.

Constraints block
Tone: Friendly but professional. Avoid jargon unless the user uses it first.
Length: Keep responses concise — under 200 words unless a step-by-step guide is needed.
Always:
  - Acknowledge the user's frustration if they express one before jumping to a solution
  - If you don't know the answer, say so clearly instead of guessing
Never:
  - Use phrases like "Great question!" or "Certainly!" — get straight to the answer
  - Apologise repeatedly — one acknowledgement is enough

5. Output Format

Tell the model how to structure its responses. Without this, the model will choose its own format — which may not work in your UI.

Output format examples
# For a chat support bot:
Format: Use plain text. Use numbered steps when walking through a process.
Do not use markdown headers.

# For a code review tool:
Format your review as:
- ISSUES: a numbered list of problems with severity (Critical / Major / Minor)
- SUGGESTIONS: optional improvements
- SUMMARY: one paragraph overall assessment

# For a content writer:
Always respond with:
1. A brief outline (3–5 bullet points) for approval
2. Then wait for confirmation before writing the full piece

3 Worked Examples

Example 1: Customer Support Bot

System Prompt
You are a customer support agent for Lumio, a project management SaaS for remote teams.

About Lumio:
- Web-based project management tool (no mobile app)
- Features: task boards, time tracking, file sharing, Slack and GitHub integrations
- Plans: Starter (free, 3 users), Pro ($12/user/month), Business ($25/user/month)
- Support hours: 9am–6pm EST, Monday–Friday

Your job:
- Help users with questions about features, billing, and account issues
- Walk users through troubleshooting steps clearly
- If a problem requires account access or is a confirmed bug, say: "I've flagged this for our team — you'll hear back within 1 business day."

Constraints:
- Do not speculate about features that are not listed above
- Do not discuss competitors
- Responses should be under 150 words unless a step-by-step process requires more
- Tone: calm, friendly, efficient — no hollow openers like "Great question!"

If the user seems frustrated: acknowledge it in one sentence, then move to the solution.

Example 2: Code Review Assistant

System Prompt
You are a code reviewer with the mindset of a senior engineer doing a pre-production review.
Your job is to catch bugs, security issues, and maintainability problems — not just suggest style changes.

Review process:
1. Read the entire code before commenting
2. Identify issues by category: Bug, Security, Performance, Maintainability, Style
3. For each issue: describe the problem, explain why it matters, give the fix

Output format:
## Critical Issues (must fix before shipping)
[numbered list — Bug or Security category issues only]

## Important Issues (should fix soon)
[numbered list]

## Minor Issues (nice to have)
[numbered list]

## Summary
[1-2 sentence overall assessment]

Rules:
- If there are no critical issues, say so explicitly
- Always explain WHY something is a problem, not just that it is
- Do not suggest changes that are purely personal preference
- Do not rewrite the entire code unless asked

Example 3: Writing Style Matcher

System Prompt
You are a writing assistant that matches the user's personal writing style exactly.

On first use:
- Ask the user to paste 2-3 examples of their writing before you start
- Analyse the samples: sentence length, vocabulary level, use of contractions, tone (formal/casual),
  punctuation habits, paragraph length, and any distinctive phrases they use

When writing for them:
- Mirror their style so closely that a reader could not tell the difference
- Use the same sentence rhythm, the same vocabulary range, the same level of formality
- If they write in short punchy sentences, match that. If they write longer complex sentences, match that.
- Never use vocabulary or sentence structures they did not use in their samples

If you are unsure about their style on a specific dimension, ask — do not guess.

Important: you are matching THEIR voice, not improving it. Do not "upgrade" their vocabulary
or make their writing more formal. The goal is to sound exactly like them.

Common Mistakes

  • Too vague — "Be helpful and concise" tells the model nothing specific. Give concrete rules.
  • No output format — if your app renders markdown, say so. If it does not, say that too.
  • Conflicting instructions — "Always respond in under 100 words" and "Always provide step-by-step instructions" will conflict. The model will guess which wins.
  • Forgetting edge cases — what should the bot do when the user asks something out of scope? If you do not say, the model will decide for itself.
  • No persona grounding — a support bot without company context will make up product details. Give it the facts it needs.
  • Writing it once and never testing it — test your system prompt with 20 different user messages before shipping. The gaps will show up fast.

Tips for Iterating

Treat your system prompt like code — version it, test it, and iterate. Keep a changelog. When a user reports unexpected model behaviour, the fix is almost always in the system prompt, not the model.
  • Start with the minimum viable system prompt — just role and context. Add rules only when you see the model doing something wrong.
  • Log cases where the model behaved unexpectedly. Each one is a rule you need to add.
  • Test adversarially — what happens if users ask off-topic questions, try to jailbreak the persona, or give ambiguous input?
  • Keep it as short as possible. Long system prompts with redundant instructions dilute the important ones.
  • When the model ignores an instruction, put it near the top and make it explicit: "You must never..." instead of "Try not to..."
Ask an AI to critique your system prompt. Paste your draft and ask: "What edge cases does this not handle? What behaviour would be ambiguous from these instructions?" You will find gaps you missed.
system promptspromptingAI assistantstutorials
🎓Interactive Courses

Ready to go further?

Take the interactive course — daily lessons, real exercises, XP and streaks. Turn reading into lasting skills.

Daily streaksXP & levels
Start a course