AI
System Prompt vs User Prompt: How to Write a System Prompt
A system prompt sets an AI model's role, rules and format for a whole chat. System prompt vs user prompt, how to write one, examples and mistakes.
A system prompt is the set of instructions an AI model receives before the conversation starts. It tells the model who it is, what it should and shouldn't do, and how to format its answers, and those instructions apply to every message that follows. The user prompt, by contrast, is each individual request a person types. Developers write system prompts to turn a general model into a specific assistant, such as a support bot, a coding helper or an agent with tools.
This guide explains what a system prompt is, the difference between a system prompt vs user prompt, where system prompts live in the APIs and apps you use, how to write a system prompt step by step, a full system prompt example, and how to test, secure and keep them affordable.
What Is a System Prompt?
Most chat models receive a conversation as a list of messages, each with a role. The system prompt comes first and frames everything else. It is usually written by the developer of an app, not by the person chatting, and the end user often can't see it.
A system prompt typically covers:
- Role: "You are a support assistant for Acme's invoicing software."
- Audience and goal: who the users are and what a good outcome looks like.
- Rules: what to do, what to avoid, when to hand over to a human.
- Context: product facts, policies or documents the model should rely on.
- Output format: length, tone, structure, language.
Even a single sentence makes a difference. Anthropic's prompting guide notes that setting a role in the system prompt focuses Claude's behaviour and tone for your use case.
System Prompt vs User Prompt
The system prompt vs user prompt split is about scope and authority:
| System prompt | User prompt | |
|---|---|---|
| Written by | The app developer (or you, in settings) | The person using the app |
| Applies to | The whole conversation | One turn |
| Typical content | Role, rules, tone, format, stable context | Questions, tasks, pasted text, files |
| Changes | Rarely; versioned like code | Every message |
| Visible to users | Usually not | Yes |
There's also a third role: assistant messages, which are the model's earlier replies in the conversation.
Which one wins when they conflict?
Models are trained to give system or developer instructions more weight than user messages. OpenAI's Model Spec describes this as a chain of command, where developer messages have greater authority than user messages. Anthropic's models also follow the system prompt as the operator's instructions.
In practice it isn't absolute. A long, specific user message can still pull a model away from a short, vague system prompt, and a determined user may try to override it on purpose. Keep both layers consistent, and don't rely on the system prompt alone for anything security-critical.
What goes where?
- System prompt: anything that should hold for every turn: persona, policies, safety rules, formatting, tool usage rules.
- User prompt: the task at hand, plus context that changes per request, such as retrieved documents in a RAG app or the file the user uploaded.
Putting per-request content in the system prompt makes it harder to cache and maintain; putting rules in the user prompt means they can be forgotten in later turns.
Where System Prompts Live
In the APIs:
- Anthropic (Claude): a top-level
systemparameter on the Messages API. - OpenAI: instructions go in a developer (formerly system) message, or the
instructionsparameter of the Responses API. - Google (Gemini): a
system_instructionparameter.
A minimal Claude example in Python:
import anthropic
client = anthropic.Anthropic()
message = client.messages.create(
model="claude-opus-5-5",
max_tokens=1024,
system="You are a helpful coding assistant specializing in Python.",
messages=[{"role": "user", "content": "How do I read a CSV file?"}],
)In the apps: consumer chat apps don't call it a system prompt, but they offer the same thing. ChatGPT has custom instructions in its personalization settings and per-project instructions; Claude has project instructions and styles; Gemini has saved info and Gems. In coding agents, project files such as CLAUDE.md and AGENTS.md act as a project-level system prompt; see our guide to AGENTS.md.
How to Write a System Prompt, Step by Step
Here is how to write a system prompt that works, in seven steps.
1. Start with the role and the job
One or two sentences: who the assistant is, who it serves and what success looks like. "You are a friendly support assistant for Acme Invoicing. You help small business owners fix billing problems quickly so they can get back to work."
2. Give the context it can't guess
Think of the model as a brilliant new employee who knows nothing about your company. Add the product facts, policies, definitions and links it needs, or tell it where to find them (for example, in retrieved documents or tools).
3. Write clear rules, with reasons
State what to do and what not to do, and say why. "Never promise refunds, because only the billing team can approve them; offer to open a ticket instead." Reasons help models handle situations you didn't list.
4. Define the output format
Length, tone, structure, language and what to do with markdown. "Answer in plain sentences, under 150 words, unless the user asks for detail. Use numbered steps for instructions."
5. Say what to do when unsure
"If the answer isn't in the provided documents, say you don't know and offer to connect the user with a human." This one line prevents many made-up answers.
6. Add an example or two
A short example conversation showing the ideal answer teaches tone and format faster than paragraphs of description. Keep examples varied so the model doesn't copy one too literally.
7. Structure it so it's easy to read
Use headings or XML-style tags (<rules>, <context>) to separate sections. Put the most important instructions where they can't be missed.
Tone tip: modern models follow instructions closely. Anthropic's guidance notes that newer Claude models are more responsive to the system prompt, and that aggressive language like "CRITICAL: You MUST…" can now cause over-triggering; plain wording such as "Use this tool when…" works better.
A System Prompt Example
Here is a complete system prompt example for a customer support assistant. Adapt the pieces to your use case:
You are Acme Invoicing's support assistant. You help small business
owners solve billing and invoicing problems in the Acme web app.
<context>
- Plans: Starter, Team, Business. Prices are on acme.example/pricing.
- Refunds and plan changes are handled only by the billing team.
- Retrieved help-center articles appear in <documents> in each message.
</context>
<rules>
- Answer only questions about Acme Invoicing. For anything else,
politely say you can only help with Acme.
- Base answers on the documents provided. If they don't cover the
question, say so and offer to open a ticket.
- Never promise refunds or credits; offer to open a billing ticket.
- Never ask for full card numbers or passwords.
</rules>
<format>
- Plain, friendly language. Under 150 words by default.
- Use numbered steps for instructions.
- End with one short question if you need more details.
</format>Notice what it does: a clear role, the facts the model can't know, rules with reasons implied by the context, a defined fallback, and a format section. It leaves out per-request content, which arrives in each user message.
System Prompt for ChatGPT, Claude and Gemini Apps
You don't need an API to use a system prompt. To set up a system prompt for ChatGPT, open its personalization settings and fill in the custom instructions: tell it about you, your work and how you want answers (for example, "be concise, use British English, show code in Python"). These apply to new chats. For a specific task, create a Project and add project instructions, which act as a system prompt for every chat in that project.
Claude works the same way with project instructions and styles, and Gemini with saved info and custom Gems. The same writing rules apply: say who you are, what you want, the format you prefer and what to avoid. For more techniques for the prompts themselves, see our prompt engineering guide.
System Prompts for AI Agents
Agents need more from their system prompt than chatbots, because they take actions:
- Tools: what each tool is for and when to use it, or not.
- Autonomy: when to act on its own and when to ask the user first.
- Stopping: what "done" looks like, and when to stop and report back.
- Safety: actions that always need confirmation, such as deleting data, spending money or sending emails.
- Progress: how and when to report what it did.
Keep the agent's system prompt focused on behaviour and let tools supply the facts, so it stays short and stable.
Test and Iterate Your System Prompt
Treat a system prompt like code:
- Collect test cases: 20 to 50 real or realistic user messages, including tricky and off-topic ones.
- Run them against each version of the prompt and save the outputs.
- Check results against what you expected, by hand or with an automated grader.
- Change one thing at a time and rerun, so you know what helped.
- Version it in your repository, with notes on why each change was made.
A good test from Anthropic's guidance: show your prompt to a colleague with no context. If they would be confused, the model will be too.
System Prompt Security and Cost
Security: assume your system prompt can leak. Users regularly coax models into revealing their instructions, and collections of leaked app system prompts circulate online. Never put API keys, passwords or private data in a system prompt, and enforce real permissions in your code, not in the prompt. Instructions hidden in web pages, emails or documents can also try to override your system prompt; our guide to prompt injection explains how to defend against it.
Cost: the system prompt is sent with every request, so a 3,000-token system prompt adds 3,000 input tokens to every call. Keep it as short as it can be while still working, put stable content first, and use prompt caching where your provider offers it, since a fixed system prompt is an ideal cached prefix.
Common System Prompt Mistakes
- Too vague: "Be helpful" tells the model nothing it doesn't already do.
- A wall of rules with no reasons: the model can't generalise to cases you didn't list.
- Contradictions: "be brief" in one place and "explain thoroughly" in another.
- Shouting: all-caps warnings can make modern models overreact.
- Stuffing in every document: use retrieval or tools for large or changing knowledge.
- Never testing: small wording changes can have big effects; measure them.
FAQ
What is a system prompt in AI?
A system prompt is a set of instructions given to an AI model before the conversation, defining its role, rules, knowledge and output format. It applies to every turn and is usually written by the app developer rather than the user.
What is the difference between a system prompt and a user prompt?
The system prompt sets the rules for the whole conversation and has higher priority; the user prompt is a single request within it. Use the system prompt for stable behaviour and the user prompt for the task and any per-request context.
Can users see the system prompt?
Usually not directly, but you should assume it can be revealed, because users can often get a model to repeat its instructions. Don't put secrets in a system prompt.
How long should a system prompt be?
As long as it needs to be and no longer. Simple assistants work well with a few hundred words; complex agents may need more. Longer prompts cost more on every call and can bury key instructions, so cut anything that doesn't change behaviour.
What is a system prompt in Claude Code?
Claude Code has its own built-in system prompt, and you add project-specific instructions through CLAUDE.md files, which it reads at the start of each session. They work like a project-level system prompt for coding conventions, commands and rules.