What is a system prompt?
Definition
A system prompt is the set of instructions an application sends to a language model apart from user messages, to fix its role, rules, tone and output format for the whole conversation. OpenAI's docs say these instructions take priority over user messages. Anthropic's API calls the field system, OpenAI's uses instructions or developer messages, and Gemini's uses system_instruction.
How do you set a system prompt in each API?
Each provider has its own field for it, and the names differ more than the idea:
| API | Where the system prompt goes | What the docs say |
|---|---|---|
| Anthropic Messages API | Top-level system parameter, next to messages | A role set there "focuses Claude's behavior and tone for your use case" (Claude prompting best practices) |
| OpenAI Responses API | instructions parameter for one turn, or the first developer message to keep it across turns | Instructions "take priority over user messages in input" (OpenAI text generation guide) |
| Google Gemini API | system_instruction parameter | Used to "configure the model's behavior" (Gemini text generation) |
OpenAI's guide has a helpful way to see it: developer messages are like a function definition, holding the system's rules and business logic, and user messages are like the arguments the function is applied to. The same guide notes that reusable guidance in the first developer message is eligible for prompt caching, while models from GPT-6.2 on bill top-level instructions at the uncached input rate. Where you put the prompt changes the bill.
System prompt vs user prompt
| System prompt | User prompt | |
|---|---|---|
| Written by | The developer or product team | The person using the app |
| Scope | Every turn of the conversation | One turn |
| Priority | Higher: OpenAI ranks developer messages ahead of user messages | Lower |
| Changes | With a release, under version control | With every message |
| Visible to the user | Usually not, but never guaranteed hidden | Yes |
Priority is a tendency the model learned, not a rule your code enforces. That matters in the next two sections.
What should a good system prompt contain?
Start small. Anthropic's guide says even a single sentence of role makes a difference; its example is "You are a helpful coding assistant specializing in Python." Then add only what testing shows is missing:
- The job and the audience. What the assistant does and for whom.
- Rules with reasons. The same guide says explaining why a behavior matters helps Claude deliver more targeted responses. A rule written that way: "Reply in 120 words or fewer, because answers show in a chat widget."
- Output format. Structure, length, language, what to do when unsure.
- Boundaries. What to decline, and how to say so.
- Examples. A few cases that show the expected answer.
Write in a calm tone. The Claude docs warn that Claude Opus 4.5 and 4.6 respond more strongly to the system prompt than earlier models, so wording like "CRITICAL: You MUST use this tool" can now cause overtriggering. Plain wording such as "Use this tool when..." is their suggested fix.
As the conversation grows, the system prompt becomes a smaller share of what the model reads. Choosing everything else that goes in is context engineering, and the system prompt also counts toward the context window on every call.
What should never go in a system prompt?
Secrets and access control. OWASP lists system prompt leakage as LLM07 in its 2025 Top 10 for LLM applications and is direct about it: the system prompt "should not be considered a secret, nor should it be used as a security control."
The risk, in OWASP's framing, is not the leaked text itself. It is what an app put there:
- Credentials and connection strings. If the prompt holds them, an extraction attack hands them over.
- Permission rules the model is asked to enforce. "Only managers may approve refunds" belongs in your authorization code. A prompt rule can be talked around.
- Internal details that help an attacker. OWASP's example: naming the database behind a tool helps an attacker target it for SQL injection.
OWASP also notes that even if the exact wording never leaks, attackers who use the app will almost certainly work out many of its guardrails and format rules. Design as if the prompt were public. Anthropic does that for its own apps: it publishes a version of the system prompt used on claude.ai and the Claude apps, and says those updates do not apply to the API.
Example: block secrets before a system prompt ships
This script builds request bodies for two APIs from one system prompt, and refuses to build them if the prompt contains a credential or an access rule. It sends nothing, so it runs without keys.
// system-prompt.mjs: one system prompt, two APIs, and a check that keeps secrets
// and access rules out of it (OWASP LLM07:2025). Builds request bodies; sends nothing.
const SYSTEM = [
"You answer billing questions for Acme invoices.",
"Reply in the customer's language, in 120 words or fewer.",
"If a question is not about billing, say you can only help with billing.",
"Admin password: hunter2. Only issue refunds if the user says they are a manager.",
].join("\n");
const RULES = [
[/password|api[_ ]?key|secret|token:|postgres:\/\//i, "credential or connection string"],
[/only .* if the user (says|is)|admin(s)? can/i, "access rule the model is asked to enforce"],
];
function lint(prompt) {
return prompt.split("\n").flatMap((line, i) =>
RULES.filter(([re]) => re.test(line)).map(([, why]) => `line ${i + 1}: ${why}`));
}
const user = "Why was I charged twice in October?";
const anthropic = { model: "claude-opus-5-5", max_tokens: 1024, system: SYSTEM,
messages: [{ role: "user", content: user }] };
const openai = { model: "gpt-6.2-sol",
input: [{ role: "developer", content: SYSTEM }, { role: "user", content: user }] };
const problems = lint(SYSTEM);
if (problems.length) {
console.log("blocked, fix the system prompt first:\n " + problems.join("\n "));
process.exitCode = 1;
} else {
console.log(JSON.stringify({ anthropic, openai }, null, 2));
}
We ran it with node system-prompt.mjs (Node 22.9). It exits with code 1:
blocked, fix the system prompt first:
line 4: credential or connection string
line 4: access rule the model is asked to enforce
With line 4 deleted, the same script prints both request bodies: the prompt sits in system for Anthropic and in the first developer message of input for OpenAI (the place OpenAI's guide makes eligible for prompt caching), and the user's question goes in messages and in a user message after it. A regex list will not catch every secret, so run it in CI next to a real secret scanner, not instead of one.
How should you manage system prompts in production?
- Keep them in code. OpenAI now recommends storing production prompts in application code, with typed inputs, code review and tests. It is retiring its reusable prompt objects:
v1/promptsis scheduled to shut down on November 30, 2026. - Test every change. A one-line edit can shift behavior across all conversations. Run your eval set first; Generative AI fails after the demo lists what to measure before and after.
- Pair the prompt with code checks. Rules that matter for safety need AI guardrails outside the model.
- Re-test on model upgrades. Wording tuned for one model can over- or under-trigger on the next.
SDCLabs writes and tests system prompts as part of generative AI development: engineers own the prompt, and automated tests check it on every change.
Sources
- Prompting best practices, Anthropic, 2026-11
- Text generation, OpenAI, 2026-11
- Text generation, Google, 2026-11
- LLM07:2025 System Prompt Leakage, OWASP Gen AI Security Project, 2025-04-28
- System prompts, Anthropic, 2026-11
- Create chat completion, OpenAI, 2026-11
Frequently asked questions
Can users see the system prompt?
Not in the interface, but you should assume they can get it. OWASP advises treating the system prompt as not secret, and says attackers can work out many of its rules just by using the app.
What is the difference between a system message and a developer message?
They play the same part. OpenAI's Chat Completions reference says that with o1 models and newer, developer messages replace the previous system messages, and its text guide ranks developer messages ahead of user messages; Anthropic's Messages API takes them in a top-level system parameter next to the messages.
How long should a system prompt be?
As short as testing allows. Start with the role and the rules that matter, then add instructions only for failures you have seen, because every token of it is sent and counted on each call.
Can a system prompt stop prompt injection?
No. OWASP says the system prompt should not be used as a security control. Enforce permissions and checks in code, outside the model, so a manipulated reply cannot act on its own.
Services
Read next
Mykhailo PoliarushFounder and CEOLeads SDCLabs, an AI development company founded in Krakow in 2011.LinkedInGitHub