TokenPad

How-to · 9 min · 7 steps

How to write a system prompt

A seven-step method for writing a system prompt that holds up in production: structure, ordering, delimiters, output format, and what to leave out.

Published August 4, 2026

A system prompt is the most-billed text in an LLM application. It is sent on every request, by every user, forever — and in a chat product it is resent on every turn of every conversation.

That economics changes how you should write it. Everything below is ordered by what actually moves output quality, and every step notes what it costs.

  1. Write the task as one imperative sentence

    Start with what the model must do, not who it is. "Classify the support ticket into billing, technical or account." If you need two sentences to state the task, you probably have two prompts, and splitting them almost always beats asking for both at once.

  2. Add a role only if it changes behaviour

    "You are a helpful assistant" describes every instruction-tuned model already and costs tokens on every request forever. "You are a triage assistant for a B2B support desk" changes vocabulary, assumed domain and default tone. Keep the second kind, delete the first.

  3. State the output format explicitly, with the exact shape

    Name the keys, show the structure, and say the response must contain nothing else. A vague format instruction is the single most common cause of a parser failing in production. Where your provider offers a structured output mode, use it — it enforces the shape rather than requesting it.

    LLM JSON Output ValidatorPull JSON out of a chatty answer and check the contract holds.
  4. Put reference material in the middle, delimited

    Models attend more strongly to the start and end of a prompt than the middle, so bulk context belongs in the low-attention zone. Wrap it in XML-style tags so the model knows where data stops and instructions begin.

    XML Tag Prompt WrapperSplit sections into tagged blocks. Eight tokens each, real accuracy gain.
  5. Group constraints instead of scattering them

    Prohibitions are followed more reliably when they sit together than when they are buried mid-paragraph. Prefer a positive statement wherever one exists — models follow "reply in one sentence" more reliably than "do not be verbose".

  6. Add two or three examples, and price them

    Examples beat instructions for format compliance, and they are the most expensive part of a prompt per unit of instruction. Cover the boundaries rather than the obvious case: one clear, one ambiguous, one that should be refused.

    Few-Shot Example FormatterPairs in, formatted examples out. Four formats, priced.
  7. Lint it, then measure what it costs per year

    Check for boilerplate, stacked tasks, missing output format and unbalanced delimiters. Then price each paragraph at your real request volume — most prompts that have been edited by several people contain a section costing four figures a year and earning nothing.

    System Prompt AnalyzerPer-section token breakdown and the yearly price of each paragraph you leave in.

What goes wrong

Putting a timestamp near the top

Prompt caching matches on an exact prefix from the first character. A date, a request id or a session identifier in the system prompt invalidates the cache on every single request, which is the most common reason caching appears not to work. If you need the date, put it immediately before the user input.

Repeating the same rule three ways

System prompts accumulate: someone hits a failure, adds an instruction, and never removes the one already covering it. Repetition does not improve compliance in proportion to its cost, and past a point it dilutes the instructions that matter.

Enumerating every edge case

Fifteen special cases usually compress into two well-phrased principles. The enumeration is how you discovered the rule; it is not how the rule needs to be expressed. Anything genuinely conditional and large belongs in a skill, loaded only when it triggers.

Frequently asked questions

How long should a system prompt be?
As short as it can be while still specifying the task, the format and the genuine constraints. There is no target length — there is a target content. If you cannot say what a paragraph changes about the output, delete it and test.
Should the system prompt or the user message carry the instructions?
The system prompt, for anything constant. It is the natural cache prefix and it is where models expect standing instructions. Put only the variable part in the user message.
Do system prompts work the same across providers?
The content transfers; the format does not. OpenAI takes the system prompt as the first message in the array, Anthropic as a separate top-level field. Porting one to the other without changing that is the most common migration bug.

Tools for this

Read next