Archive/PROMPTS

Anatomy of a production system prompt

Role, context, rules, tools, format, fallbacks and examples. A section-by-section guide to writing system prompts that behave predictably at scale.

Anatomy of a production system prompt

A system prompt is the set of instructions a model receives before every conversation. In a demo, it can be one sentence. In production, it is effectively part of your application code: it decides how the product behaves across thousands of situations nobody tested by hand, and every word is paid for on every request.

Good production prompts share a recognisable structure. This guide walks through the seven sections that matter, the order that works best, what to leave out, and how to test and maintain prompts as they evolve. For complete, copy-ready examples built on this structure, see system prompt templates for production.

The seven sections

Sections of a production system prompt
SectionPurposeTypical length
1. Role and goalWhat the assistant is for and what success looks like1–3 sentences
2. ContextFacts the model needs: product, audience, date, constraintsA short paragraph or list
3. Knowledge rulesWhich sources to trust and what to do when they are silent2–5 rules
4. Behaviour rulesHow to act: tone, length, scope, escalation3–10 rules
5. ToolsWhen and how to use each tool, with confirmation rules1–3 lines per tool
6. Output formatThe exact shape of responsesA template or schema
7. Examples (optional)One to three demonstrations of tricky casesAs short as possible

1. Role and goal

Describe the job, not a personality. "You are the support assistant for Acme's invoicing software. Your goal is to resolve billing questions accurately in as few messages as possible" is more useful than "You are a world-class, friendly expert." Persona adjectives rarely change behaviour measurably; a concrete goal does.

2. Context

Give the model facts it cannot know: what the product is, who the users are, today's date, the user's plan or locale if relevant. Keep it factual. If context changes per request (user name, account tier), insert it with clearly labelled variables, and keep the stable parts first so prompt caching can reuse them.

3. Knowledge rules

Say where answers should come from and what to do when the sources do not cover a question. This single section prevents most hallucinated policies.

For grounding and citation techniques, see prompting for citations that actually check out.

4. Behaviour rules

Rules about tone, length, scope and escalation. Write them as positive instructions that describe the desired behaviour, rather than prohibitions; "don't" instructions are unreliable and can even plant the idea you want to avoid; see why "don't do X" instructions fail.

Make every rule testable. "Be concise" is vague; "keep answers under 120 words unless the user asks for detail" can be checked automatically.

5. Tools

For each tool, say when to use it, what inputs it needs, and what to do when information is missing. Mark actions that require confirmation: "Before issuing a refund, summarise the amount and reason and ask the user to confirm." Detailed tool descriptions belong in the tool definitions; the system prompt covers when and why.

6. Output format

Specify the exact shape: plain text with a length limit, Markdown with specific headings, or a JSON schema. Show a literal template rather than describing it. For machine-readable output, see structured output without JSON mode.

7. Examples

Examples are powerful and easy to misuse. One to three short examples of difficult cases, such as an ambiguous request or a refusal, often help more than a page of rules. But models copy examples closely, including their length, phrasing and content. Read few-shot examples that don't backfire before adding them.

Order and formatting

What to leave out

Common anti-patterns, and what to do instead

A few patterns appear in almost every prompt that has grown without review:

Testing and maintenance

Treat the system prompt as code:

  1. Version it in source control with a changelog.
  2. Pair it with an eval set covering normal, edge-case and adversarial inputs. Run the eval for every change.
  3. Change one thing at a time, so you know what caused an improvement or a regression.
  4. Read changed outputs, not just scores. A new rule can quietly change behaviour on cases you did not intend to affect.
  5. Prune regularly. Remove rules that no eval case depends on; if behaviour does not change, the rule was not needed.
  6. Re-test when models change. Prompts tuned for one model can behave differently on another.

A skeleton to start from

textsystem-prompt-skeleton
<role>
You are {assistant} for {product}. Your goal: {measurable goal}.
</role>

<context>
Users: {who}. Today: {date}. User plan: {plan}.
</context>

<knowledge>
Answer only from <docs>. If <docs> does not cover the question, say so and offer {fallback}.
</knowledge>

<behaviour>
- {length rule}
- {tone rule}
- Escalate to a human when: {triggers}.
</behaviour>

<tools>
- {tool}: use when {condition}; confirm with the user before {risky action}.
</tools>

<format>
{template or schema}
</format>

Frequently asked questions

What is a system prompt?

A system prompt is the set of standing instructions given to a language model before the user's messages, defining its role, rules, knowledge sources, tools and output format for every conversation.

How long should a production system prompt be?

Long enough to cover the behaviours you test and no longer. Many effective production prompts are a few hundred words. Every rule should correspond to a behaviour you can check in an eval.

What is the best structure for a system prompt?

A reliable order is: role and goal, context, knowledge rules, behaviour rules, tools, output format and optional examples, with clear delimiters between sections and stable content placed first.

How do I test changes to a system prompt?

Run the new and old versions against the same eval set covering normal, edge-case and adversarial inputs, compare scores with confidence intervals, and read every output that changed.

SP
WRITTEN BYSana PatelResearch editor. Translates papers into diagrams people finish reading.

Keep reading

Liked this? The Sunday Diff has one like it every week.