← All news

News / Learn / Prompt engineering

How do you write a good system prompt?

You'll be able to write a system prompt that sets a model's role, rules, and output format clearly enough to guide every reply.

A system prompt is the set of instructions a developer sends to a model before the user's message. It tells the model who it is, what it should do, what it must avoid, and how to format its answers. The model reads it on every request, so it shapes the whole conversation.

Most product behavior comes from the system prompt. A clear one makes replies consistent, on-brand, and easier to parse in your code. A vague one leads to drift, odd tone, and answers that break your app.

The system prompt sits in a separate message role, usually labeled system, placed ahead of the user turns. Models are trained to give it weight, so instructions there tend to hold better than the same text pasted into a user message.

A solid system prompt covers four things: the role and goal, the context the model needs about the product or user, the rules and limits, and the output format. State each one in plain sentences. Explain the reason behind a rule when you can, because a model applies a reason to cases you did not list.

Keep the prompt focused. Long prompts that repeat themselves or contradict each other make behavior less predictable. Put the most important rules near the start and the end, since models pay the most attention to those spots. Use simple section headers or short lists so the structure is easy to read.

Treat the system prompt as code. Store it in version control, change one thing at a time, and check the effect against a fixed set of test inputs. A change that fixes one case can quietly break another.

A system prompt for a support assistant that answers from a product's help docs.

You are a support assistant for Acme Notes, a note-taking app.

Goal: Help users solve problems using the help articles provided in the conversation.

Rules:
- Answer only from the provided articles. If they do not cover the question, say so and suggest contacting support.
- Do not promise refunds, features, or dates.
- Keep answers under 120 words.

Format: Start with a one-sentence answer, then up to three numbered steps.

A short sketch to show the idea. Check the official docs of the tool you use.

  • Writing a vague role Say who the model is, who it talks to, and what success looks like. 'Helpful assistant' gives little guidance.
  • Listing rules with no reasons Add a short reason to key rules. The model can then handle cases the list did not anticipate.
  • Contradicting yourself Read the whole prompt for conflicting rules. When two rules clash, the model picks one unpredictably.
  • Assuming the prompt is a security boundary A system prompt guides behavior but does not enforce it. Enforce limits in your code, such as access checks and output validation.
  • Never testing changes Keep a fixed set of sample inputs and compare outputs after each edit, so you catch regressions early.

Read about few-shot prompting, structured output, and prompt injection. Then build a small eval set and learn how to score prompt changes against it.

Is the system prompt hidden from users?

Not reliably. Users can sometimes coax a model into revealing it. Do not put secrets, keys, or private data in the system prompt.

Should the system prompt be long?

As long as it needs to be and no longer. Cut repeated and vague lines. Test whether each rule changes the output.

Does the same prompt work on every model?

Often close, but not identical. Models differ in how they follow instructions, so test your prompt on the model you deploy.

Can I put examples in the system prompt?

Yes. A few examples of good input and output often clarify format and tone better than more description.

Written with AI by CapyLaunch. Spotted a mistake? Email hello@capylaunch.com.