How to Write a System Prompt for an AI Agent

9 min readUpdated

A system prompt sets an agent's standing role. Write it in sections: role, scope, tone, tools, boundaries, escalation and output format. Keep rules specific, say what to do when unsure, then test it on realistic cases, including ones it should refuse, and revise.

A system prompt is the set of standing instructions that shapes how an AI assistant behaves across every conversation. It defines who the assistant is, what it handles, how it speaks, what it may use and where it must stop. When you set up an agent or a support assistant, the system prompt is the most important piece of text you write. This guide explains what to include, shows a complete example and gives you a simple method to test and improve it.

What a system prompt is, and what it is not

A system prompt describes the assistant, not the task. It answers questions such as: What is your role? What topics may you help with? How should you sound? What tools can you use? What must you never do? When should you hand the conversation to a person?

A task brief, by contrast, describes one piece of work: a goal, inputs and a finish line. The task checklist covers briefs. Keep the two apart. Standing rules in the system prompt, task details in each message. That keeps both short and makes problems easier to fix.

Where the system prompt goes depends on the product. Many tools offer an instructions field for assistants you configure. If yours does not, you can paste it at the start of a conversation. Check the provider's documentation for the options available to you.

The seven sections of a good system prompt

Write the prompt in labeled sections. Labels make it easy to scan, easy to edit and easier for the model to follow. Tag-style labels such as <role> work well, and plain headings do too.

1. Role

Say who the assistant is and what it is for, in one or two sentences. Include whom it serves. "You are the support assistant for a scheduling app used by small clinics. You help clinic staff solve problems quickly and politely."

2. Scope

List what the assistant may help with, and what it must not. Be concrete. "Account setup, billing questions and how to use features" is useful. "Anything related to our product" is not. Say what to do with out-of-scope requests: decline briefly and point to the right place.

3. Tone

Describe how the assistant should sound in a few words, and what to avoid. "Friendly, calm and plain-spoken. No jargon, no exclamation marks." Tone is easy to over-describe, so keep it short, and add an example reply if tone matters a lot.

4. Tools and knowledge

List the tools and sources the assistant may use, and when. State what to rely on: "Answer only from the help articles below." Say what to do when the answer is not there: "Say you do not know. Never guess prices, dates or policies."

5. Boundaries

State the things the assistant must never do, and the actions that need approval. Examples: never ask for passwords, never promise refunds, never give legal or medical advice, always ask before changing a record. Boundaries work best as short, separate lines rather than a paragraph.

6. Escalation

Define when to hand over to a person, how, and what to include. "When the customer asks for a refund, reports a data problem or is clearly upset, summarize the issue in two sentences and give them the support address." A good escalation rule saves the customer from repeating themselves.

7. Output format

Say what replies look like: length, structure and how to end. "Start with the answer. Use a numbered list for steps. Keep replies under 120 words unless asked for detail. End by asking whether the problem is solved."

A complete worked example

The prompt below applies all seven sections. Replace the details with your own.

Prompt
You are the support assistant for {company_name}, which offers {product_description}. You help customers solve problems quickly and politely. You speak for the company, so accuracy matters more than speed.

<scope>
You may help with: {in_scope_topics}
You must not help with: {out_of_scope_topics}
If a request is out of scope, say so briefly and point to the right place.
</scope>

<tone>
{tone}. No jargon. No exclamation marks.
</tone>

<knowledge>
Answer only from the material below. If the answer is not there, say you do not know. Never guess prices, dates, policies or technical details.
{knowledge_material}
</knowledge>

<boundaries>
- Never ask for passwords or full payment card numbers.
- Never promise a refund, a discount or a delivery date.
- Never give legal, medical or financial advice.
- Ask before taking any action that changes a customer record.
</boundaries>

<escalation>
Hand over to a person when {escalation_rules}. Summarize the issue in two sentences and give this contact: {handoff_contact}
</escalation>

<answer_format>
Start with the answer. Use a numbered list for steps. Keep replies under 120 words unless the customer asks for detail. End by asking whether the problem is solved.
</answer_format>

The System Prompt for a Customer-Support Assistant template gives you this structure with every variable explained.

Writing rules that work

The sections tell you what to include. These habits make each line effective.

Be specific. "Be helpful" tells the assistant nothing. "Answer in under 120 words and end with a question about whether it is solved" tells it exactly what to do.

Say what to do, not only what not to do. A rule such as "do not guess" is stronger with an alternative: "if you do not know, say so and offer to hand over to a person."

Give the reason when it matters. "Never ask for card numbers, because chat messages are stored" helps the assistant apply the rule in cases you did not list.

Resolve conflicts. If one line says "always give a complete answer" and another says "keep replies short", the assistant has to choose. Decide which wins and say so.

Keep each rule in one place. Repeating a rule in several sections invites drift when you edit one copy and forget the others.

Put the hard rules where they are easy to find. A boundary buried in a long paragraph is easier to miss than the same rule on its own line.

Tools and tool rules

If the agent can take actions, such as searching, reading files, sending messages or changing records, the system prompt needs rules for them. Say which tools it may use freely, which it must ask about first and which it must never use. State how to handle failures: try once more with a different approach, then report the error plainly instead of inventing a result. The Tool-Use Rules and Boundaries template covers this in detail.

How to test a system prompt

A system prompt is a draft until you have tested it. Testing does not need software. A short list of cases and an hour of reading is enough to find the biggest problems.

  1. Write 8 to 12 test cases. Use realistic messages, not ideal ones. Include some with typos, some with two questions at once and some with emotion.
  2. Include cases that should be refused. Ask something out of scope, ask for a forbidden promise and share something sensitive. Check that the boundaries hold.
  3. Include a case where the answer is not in the knowledge. The assistant should say it does not know, not invent something.
  4. Include a case that needs escalation. Check that the handover is clear and complete.
  5. Read each reply against your rules. Note which rule was followed, ignored or misapplied.
  6. Change one thing at a time. Edit the prompt, rerun the failing cases and then rerun the passing ones to check that nothing broke.

Keep the test cases in a file. Each time you change the prompt, run them again. Over time, this list becomes a safety net.

Common problems and fixes

Problem Likely cause Fix
Replies are too long Format rule missing or buried Add a length limit in the output section
It guesses when unsure No rule for missing information Add "say you do not know" and a test case
It ignores a boundary Rule is vague or in a long paragraph Make it specific, put it on its own line
The tone drifts Tone described loosely Add two words to avoid and a short example
It handles out-of-scope requests Scope is too broad List what it must not help with
Handover is confusing Escalation rule lacks detail Say how to hand over and what to include

Keeping it maintainable

Treat the system prompt like code. Keep it in one place, date your changes and write down why you made each one. When a new problem appears, add a test case first, then fix the prompt. When the prompt gets long, look for repeated rules and for instructions that really belong in a task brief.

Product features change often, so check the provider's documentation for how system instructions are handled in the product you use. The structure described here stays useful either way.

Next steps

Start from the support assistant template and adapt it. Add tool rules from Tool-Use Rules and Boundaries for an Agent if your agent takes actions. For the bigger picture, read How to Write Prompts for AI Agents, and for common errors, 10 Common Prompt Mistakes.

Try these templates

Frequently asked questions

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

A system prompt holds standing instructions that apply to every conversation, such as role, scope and rules. A normal prompt is a single message with a task. Keeping them apart makes both shorter and easier to maintain.

How long should a system prompt be?

Long enough to cover the seven sections clearly, and no longer. Many work well at 200 to 400 words. If it keeps growing, check for repeated rules and instructions that belong in the task instead.

Where do I put the system prompt?

Many products and tools have an instructions or system field for assistants you configure. If yours does not, paste it at the start of a conversation. Check the provider's documentation for where it goes.

Why does the agent ignore one of my rules?

Common causes are a vague rule, two rules that conflict or a rule buried in a long paragraph. Make the rule specific, put it in its own line or section and test it with a case that should trigger it.

How do I keep an agent from guessing?

Tell it what to do when it does not know: say so, ask a question or hand over to a person. Give the sources it may use, and add a test case where the answer is not in them.

Keep reading