EN

Language

Our editions

Written for each audience, not translated word for word.

What a system prompt is and how to write one

ExplainerBy Lucas Matías García TorresUpdated Data checked 6 min read

Reviewed by Lucas Matías García Torres on . How we work.

Leer en español

A 3D lattice of thin steel lines and nodes with a few pathways lit in orange, like a neural network

Short answer

A system prompt is the set of instructions an application gives a language model before the user's message: the role, the rules, the tone and the output format. OpenAI takes it as an instructions parameter or a developer message, Anthropic as a system parameter and Google as a system instruction, and OpenAI says developer instructions are prioritized ahead of user messages. It is billed as input on every call, so it is worth caching, and OWASP warns it should never hold secrets.

Prices and limits change often: check the vendor's page before you pay. How we make money.

A system prompt is the set of instructions an application gives a language model before the user says anything: who the model should act as, what it may and may not do, which tone to use and how to format the answer. When a shop's support chatbot answers only questions about orders and replies in three short sentences, that behavior usually comes from its system prompt, not from the model itself. This guide explains what a system prompt is, where it goes in the OpenAI, Claude and Gemini APIs, how much weight models give it, what it costs and why it must never hold a secret.

Where the system prompt goes in each API

Each provider has its own name and slot for these instructions. The idea is the same everywhere: they travel with the request, separately from the user's message.

Table: where system instructions go (official documentation, checked October 28, 2026)

Provider Where it goes What the documentation adds
OpenAI The instructions parameter, or a message with the developer role Instructions passed this way take priority over the prompt in the input
Anthropic (Claude) The system parameter of a Messages request Setting a role there focuses the model's behavior and tone
Google (Gemini) The system_instruction parameter Used to configure the model's behavior

One detail catches people out on OpenAI: the instructions parameter applies only to the request it is sent with. If you chain turns with previous_response_id, the instructions from earlier turns are not carried over, so your application has to send them again every time.

Who wins when instructions conflict

OpenAI says developer messages, the instructions from the application's developer, are prioritized ahead of user messages from the person typing. It compares the two to a function and its arguments: the developer message holds the rules and business logic, and the user message provides the input those rules are applied to.

That priority describes how the model is meant to behave; it is not a lock. A user, or text hidden in a web page or a document the model reads, can still try to talk the model out of its instructions, which is the attack described in our guide to prompt injection. A system prompt makes the intended behavior much more likely; it does not make other behavior impossible.

Wording matters too. Anthropic notes that Claude Opus 4.5 and Claude Opus 4.6 respond more strongly to the system prompt than earlier models, and that rules written to shout at older models can now make them overreact. Its suggestion is to replace something like "CRITICAL: You MUST use this tool when..." with plain wording such as "Use this tool when...".

What a good system prompt contains

Most production system prompts cover the same six things:

  1. A role. One sentence about who the model is acting as. Anthropic says even a single sentence makes a difference.
  2. The task and the audience. What the assistant is for and who it talks to.
  3. Rules. What it should do, what it must not do, and what to do when it is unsure, such as offering to hand over to a person.
  4. Context. Product facts, policies or reference text the model needs on every turn.
  5. The output format. Length, structure, language and anything your software parses.
  6. Examples. A few sample exchanges showing the answer you want.

Long prompts are easier for the model to follow when each part is clearly marked. Anthropic recommends wrapping each type of content in its own XML tag, such as <instructions> or <context>, and says this reduces misinterpretation; Markdown headings do a similar job. Our prompt engineering basics cover how to phrase each instruction.

An example for a support chatbot

Here is a short system prompt for an imaginary online bicycle shop. It is an illustration, not a template that works unchanged everywhere:

You are the customer support assistant for an online bicycle shop.

<rules>
- Answer only questions about orders, delivery, returns and the products in <context>.
- If the answer is not in <context>, say you are not sure and offer to pass the
  conversation to a person.
- Never ask for card numbers or passwords.
- Reply in the customer's language, in three sentences at most.
</rules>

<context>
Delivery: 2 to 4 working days in Spain. Returns: 30 days, free of charge.
</context>

Each line maps to one of the six parts above: the role in the first line, rules in their own block, and the facts the model may use in a separate block. Everything a customer asks is then read in the light of those instructions.

What a system prompt costs

The system prompt is billed as input tokens on every call, because the model has to read it each time. In our worked example of a support chatbot's monthly cost, a 1,200-token system prompt sent on four turns accounts for 4,800 of the 6,500 input tokens in each conversation. A long prompt is not a problem in itself, but every token in it is multiplied by your traffic.

Prompt caching is the usual answer, and the system prompt is the ideal candidate because it repeats exactly. Two rules from the providers decide whether it works:

  • Static content goes first. Anthropic builds its cache in a fixed order, tools, then system, then messages, and a change at one level invalidates that level and everything after it. A date, a user's name or anything else that changes at the top of the system prompt breaks the cache for the whole request.
  • There is a minimum length. OpenAI caches prompts from 1,024 tokens on GPT-5.6 and later models, and Anthropic from 512 tokens on its 5.5 models. Shorter prompts are simply processed at the normal price.

Our guide to prompt caching explains the discounts, and the context window sets the outer limit on how long the prompt and conversation can grow.

Why a system prompt is not a secret or a lock

OWASP, the open security project, lists system prompt leakage among the main risks of applications built on language models. Its guidance is blunt: the system prompt "should not be considered a secret", and it should not be used as a security control either. Users can often coax a model into revealing its instructions, and nothing guarantees it will refuse.

Three practical consequences follow from OWASP's guidance:

  • Keep credentials out. Passwords, API keys and connection strings do not belong in a system prompt.
  • Enforce limits in code. Rules such as who may see which data or how much a user may spend must be checked by your software, not left to the model's instructions.
  • Check outputs independently. OWASP considers a separate system that inspects the model's output preferable to relying on system prompt instructions alone.

Write every system prompt as if a curious user will read it one day, because one may.

Custom instructions in consumer apps

You do not need an API to use the same idea. In ChatGPT, custom instructions are guidance you write yourself in its Personalization settings, and the assistant takes them into account in your chats; our guide to ChatGPT memory explains how they sit alongside saved memories. The difference with an application's system prompt is who writes it: you, for yourself, instead of a developer, for every user of a product.

How we checked

We read OpenAI's text generation guide and its prompt caching guide, Anthropic's prompting best practices and prompt caching documentation, Google's Gemini text generation documentation and the OWASP entry LLM07:2025 System Prompt Leakage on October 28, 2026. The figure of 4,800 input tokens comes from the example in our chatbot cost guide. The sample system prompt is our own illustration and has not been tested against any particular model.

What we checked

  • OpenAI: the instructions parameter gives the model high-level instructions on how to behave and takes priority over a prompt in the input parameter; it only applies to the current request, and with previous_response_id the instructions of previous turns are not present; developer messages are prioritized ahead of user messages, and the two can be thought of like a function and its arguments. (OpenAI, )
  • Anthropic: setting a role in the system prompt focuses Claude's behavior and tone, and even a single sentence makes a difference; the Messages API takes it in the system parameter; wrapping each type of content in its own XML tag reduces misinterpretation; Claude Opus 4.5 and Claude Opus 4.6 are more responsive to the system prompt than previous models, and aggressive wording such as "CRITICAL: You MUST use this tool when..." should be softened. (Anthropic, )
  • Google: Gemini models can be guided with system instructions passed in a system_instruction parameter. (Google, )
  • Anthropic prompt caching: cache prefixes are created in the order tools, system, then messages, and changes at each level invalidate that level and all subsequent levels; the minimum cacheable prompt is 512 tokens on Claude Opus 5.5, Sonnet 5.5 and Haiku 5.5. (Anthropic, )
  • OpenAI prompt caching: the minimum cacheable prompt is 1,024 tokens for GPT-5.6 and later. (OpenAI, )
  • OWASP LLM07:2025 System Prompt Leakage: the system prompt should not be considered a secret nor used as a security control; credentials and connection strings should not be in it; training a model not to reveal its system prompt is no guarantee; critical controls must be enforced independently of the model; an independent system that inspects the output is preferable to system prompt instructions. (OWASP GenAI Security Project, )

What may change

  • Parameter names and caching rules change as providers update their APIs. This page is reviewed quarterly.

Frequently asked questions

What is a system prompt in simple terms?

It is the set of standing instructions an application gives a language model before the conversation starts: who the model should act as, what it may and may not do, which tone to use and how to format answers. The user usually never sees it, but it shapes every reply the model gives in that application.

What is the difference between a system prompt and a user prompt?

The system prompt comes from whoever builds the application and sets the rules; the user prompt is what the person types. OpenAI says developer messages are prioritized ahead of user messages, and compares them to a function and its arguments: the developer message holds the logic, the user message provides the input.

Can users see the system prompt?

Not directly, but it is not safe to assume they never will. OWASP warns that a system prompt should not be treated as a secret, because users can often coax a model into revealing it and training a model to refuse is no guarantee. Keep passwords, keys and internal details out of it.

Does the model always follow the system prompt?

No. Models are designed to give it priority, but a user or text hidden in a document or web page can try to override it, which is called prompt injection. Anything that must never happen, such as showing another customer's data, has to be enforced by your own software, not by the prompt.

How long should a system prompt be?

As long as the job needs and no longer, because it is billed as input on every call. Longer prompts can be cached once they pass the provider's minimum, 1,024 tokens on OpenAI's GPT-5.6 and later models and 512 tokens on Anthropic's 5.5 models, which makes the repeated part much cheaper.

Where do I put the system prompt in the OpenAI API?

In the instructions parameter or in a message with the developer role. OpenAI notes that the instructions parameter only applies to the request it is sent with: if you chain turns with previous_response_id, earlier instructions are not carried over, so your application has to send them again on every turn.

Sources

  1. Text generation (OpenAI API guide): the instructions parameter, message roles and prompts in code, OpenAI. Accessed October 28, 2026.
  2. Prompting best practices (Claude Platform Docs): roles in the system prompt, XML tags and model-specific guidance, Anthropic. Accessed October 28, 2026.
  3. Text generation (Gemini API): system instructions and other configurations, Google. Accessed October 28, 2026.
  4. Prompt caching (Claude API): automatic caching, minimum lengths by model, lifetime and pricing multipliers, Anthropic. Accessed October 28, 2026.
  5. Prompt caching (OpenAI API guide): on by default, 1,024-token minimum, write and read rates for GPT-5.6 and later, OpenAI. Accessed October 28, 2026.
  6. LLM07:2025 System Prompt Leakage (OWASP Top 10 for LLM Applications), OWASP GenAI Security Project. Accessed October 28, 2026.

Spotted an error or an outdated price? Tell us and we will fix it.

Change history

  • : First published. Checked against OpenAI, Anthropic and Google documentation and the OWASP entry on system prompt leakage on October 28, 2026.

Next review: .

Part of our Language Models Explained guide.

Other topics