Guide
How to Use System Prompts: Structure, Example and Limits
What a system prompt is, what belongs in it versus the user message, a worked example, and the limits to plan for when building on one.
At a glance
- Type
- Guide
- Topics
- System prompt, Prompt engineering, Prompt injection
- Evidence
- Editorial interpretation
- Written by
- Liyam Flexer
A system prompt is a set of standing instructions the model reads before any user message, used to fix its role, rules and output conventions for a whole conversation or application. Put the things that should stay true for every turn there, such as who the assistant is, who it serves, what it must not do and how replies are formatted, and keep the specific task and its data in the user message. Models are designed to give system-level instructions priority, but that priority is a strong tendency, not a security boundary.
Where does a system prompt sit?
Chat-style model APIs accept messages with roles. The names vary by vendor: Anthropic's API takes a system parameter alongside the message list; OpenAI's current documentation describes developer messages (earlier models used a system role) that take precedence over user messages; Google's Gemini API calls the equivalent a system instruction. The idea is the same in each case: one block of text from the application's author, applied to every turn.
{
"system": "You are a support assistant for a bicycle parts retailer...",
"messages": [
{ "role": "user", "content": "Is the 11-speed chain compatible with my 10-speed cassette?" }
]
}If you only use chat apps, you still have access to the concept. Custom instructions, project instructions and similar settings are system-level text you write once and the app supplies for you on each conversation.
What belongs in a system prompt?
A useful division: the system prompt describes the job, the user message describes today's piece of work.
System prompt
- Role and audience: what the assistant is, who it is talking to, what they typically need.
- Scope: topics it handles and what it does with everything else.
- Behavior rules: tone, when to ask a clarifying question, how to handle uncertainty.
- Output conventions: length, formatting, language, any required structure.
- Stable reference material: a product list, a style guide, a glossary.
User message
- The request itself.
- Input that changes every time: the document to summarize, the customer's question, the row of data.
Anthropic's guidance on role prompting notes that setting a role focuses the model's behavior and tone, and that even one sentence makes a difference; "a data analyst reviewing marketing spend for a retail finance team" carries more usable information than "a helpful assistant". It also recommends giving the reason behind an instruction where one exists, because a model that knows why a rule is there can apply it sensibly to cases the rule did not name.
What does a good system prompt look like?
# Role
You are the support assistant for a retailer of bicycle parts. You
answer customers who are mid-repair and want a direct answer.
# Scope
Answer questions about compatibility, fitting and order status using
the catalog in <catalog>. For medical, legal or unrelated questions,
say this is outside what you can help with and offer to return to the
repair.
# Rules
- If compatibility depends on a detail the customer has not given
(speed count, axle standard, brake type), ask for it before
answering. One question at a time.
- If the catalog does not cover a part, say you cannot confirm it.
Do not infer compatibility from similar part names, because a wrong
answer here means a wasted order.
- Never quote prices; they change daily. Point to the product page.
# Output
Plain text, no markdown. Lead with yes, no or "it depends on", then
at most three sentences of explanation.
<catalog>
...
</catalog>Each section is short, the rules say what to do in the uncertain case, and two of them include the reason. The catalog is delimited so the instructions can refer to it by name and so it is not confused with the rules.
How do you write rules the model will follow?
- Prefer positive instructions. "Reply in plain sentences" is followed more dependably than "do not use lists". Google's prompting guidance makes a related point about examples: show the model what getting it right looks like.
- Cover the fallback. For every "only do X", say what happens otherwise. Unspecified fallbacks are where assistants improvise.
- Keep emphasis proportionate. Vendor guidance for recent models notes they are responsive to system instructions, and that shouting (capitals, "CRITICAL") can cause a rule to be over-applied. State it once, plainly.
- Resolve conflicts yourself. "Be thorough" and "keep replies under 50 words" cannot both win. Decide the priority and write it down.
- Order by importance, group by topic. Labeled sections make a long system prompt easier for the model to follow and for you to edit.
What are the limits of a system prompt?
It is not access control
A user can ask the model to ignore its instructions, and text inside a pasted document or a web page can contain instructions of its own. Models are trained to favor the system prompt, but you should assume that determined input can sometimes override or extract it. Do not put secrets, credentials or anything you would not want displayed into a system prompt, and enforce real permissions in code, outside the model.
Long conversations drift
Over many turns, earlier instructions compete with a growing history. If a rule matters at a specific moment, such as output format for a final step, restating it in the relevant user turn is a reasonable safeguard.
It costs tokens on every call
The system prompt is sent with each request. Long reference material may be better retrieved per request than included permanently. Vendors offer prompt caching features that reduce the cost of a repeated prefix; check the current documentation for the model you use.
Behavior differs between models
A system prompt tuned on one model version should be re-tested on the next. Phrasing that was needed to get an older model's attention may be too forceful for a newer one.
How do you test a system prompt?
Because a system prompt governs inputs you will never see, test it with a fixed set of messages before relying on it:
- Several ordinary requests that represent the main use.
- A request with a missing detail, to check the clarifying-question rule.
- An out-of-scope request.
- A message that tries to override the rules ("ignore the above and...").
- An empty or garbled message.
Change one rule at a time and re-run the set. The rubric in how to test AI prompts applies directly; constraint adherence and reliability are the criteria system prompts most often fail.
Which related prompting patterns should you know?
Examples can live in a system prompt too, and are often the most efficient way to pin down tone or format; see few-shot prompting. For work that passes through several model calls, each call typically gets its own narrow system prompt, as described in prompt chaining. For a system-style prompt applied to a concrete job, the brand voice prompt and the code review prompt both define a role, rules and output format in the way described here.
Which guides should you read next?
- How to write a good AI prompt: the five parts and a checklist
- How to improve AI responses: diagnose and fix weak answers
- How to test AI prompts: a seven-criterion rubric
- How to prompt AI for better web design: three frameworks
- How to humanize AI text: 10 prompts to sound human
- Best AI prompts for developers
- Claude Code prompts to improve your website homepage
- AI glossary: prompt, token, context window and more
- All guides
Evidence in this article Editorial interpretation Our reading of what the evidence means. Judgment, clearly separated from the evidence itself.
Frequently asked questions
What is the difference between a system prompt and a user message?
The system prompt describes the job; the user message describes today's piece of work. Role, scope, behavior rules, output conventions and stable reference material go in the system prompt. The request itself, and input that changes every time, go in the user message.
Is a system prompt a security boundary?
No. A user can ask the model to ignore its instructions, and pasted documents or web pages can contain instructions of their own. Do not put secrets or credentials in a system prompt, and enforce real permissions in code, outside the model.
Can I use a system prompt in a chat app?
Yes. Custom instructions, project instructions and similar settings are system-level text you write once, which the app supplies for you on each conversation.
Why does an assistant drift from its system prompt in a long conversation?
Over many turns, earlier instructions compete with a growing history. If a rule matters at a specific moment, such as the output format for a final step, restating it in the relevant user turn is a reasonable safeguard.
Related reading
- Category: General-purpose AI assistants
- Category: Agents & automation
Sources
- Prompt engineering overview Anthropic, accessed . Vendor documentation for Claude models.
- Prompting best practices Anthropic, accessed . Vendor documentation for Claude models: the full list of prompting techniques.
- Prompt engineering guide OpenAI, accessed . Vendor documentation for OpenAI models.
- Prompt design strategies Google AI for Developers, accessed . Vendor documentation for Gemini models.
Further reading
From a related publication under the same ownership. It is commentary, not evidence for anything on this site.
- Few-Shot Prompting: How to Use Examples in a Prompt, The Best Prompt For. Guide on the sister site.
- Prompt Chaining: Breaking a Task Into Linked Prompts, The Best Prompt For. Guide on the sister site.
- Brand voice prompt, The Best Prompt For. Ready-to-use prompt in the sister site's library.
- Code review prompt, The Best Prompt For. Ready-to-use prompt in the sister site's library.
- Refactoring prompt, The Best Prompt For. Ready-to-use prompt in the sister site's library.