Skip to content
AgenticAIWiki
  1. Learn
  2. Part 2
  3. 11. Explicit criteria, roles and XML tags
  4. 11.1

Lesson 11.1 · 1 of 7 · 5 min read · Reviewed 24 Nov 2026

System prompts that read like a spec

By the end, you can

  • Write a system prompt that reads like a short spec.
  • Name the parts a good system prompt covers.

Imagine giving a smart new colleague a task with no background. They’d ask: what’s this for, who reads it, what does good look like, what must I avoid? A good system promptSystem prompt: Instructions passed in the top-level system field that set the model’s role, rules and context for the whole conversation. answers those questions before they’re asked.

A simple shape

Goal: Answer billing questions for Payly, a payroll app for firms with 5-50 staff.
Audience: Office managers, not accountants. Plain words, no jargon.
Rules:
- Only answer from the help-centre articles provided.
- Never promise refunds; route refund requests to a person.
- If unsure, say so and offer to connect them with support.
Output: 2-4 short paragraphs. End with a link to the article you used.

Why a spec beats a persona

“You are a world-class support agentAgent: A system where a model decides its own next steps, calling tools in a loop until the task is done.” sounds strong, but Claude still doesn’t know the product, the users or the rules. Context changes behaviour. Flattery doesn’t.

Test it like code

Run the prompt on real inputs, including awkward ones. Each failure usually points at a missing line in the spec. Chapter 15.3 turns that into a habit.

Key points

  • A strong system prompt reads like a brief for a new colleague: the goal, the audience, the rules and the output.
  • State the context Claude can't guess: who the users are, what the product does, what good looks like.
  • Put the most important constraints plainly, not buried in a paragraph.
Hands-on labRuns in the Playground

Rewrite a vague prompt as a spec

Turn a one-line persona prompt into a four-part spec and check it covers goal, audience, rules and output.

You will have: A spec dictionary, a build function and a checker that scores both prompts, plus a simulated reply to a refund request.

Steps

  1. Run the starter: the checker scores the vague prompt and the unfinished spec.
  2. Add the Audience, Rules and Output entries to SPEC.
  3. Rerun until the spec scores 4/4.
  4. Read the simulated reply to a refund question and check it does not promise one.
  5. Add a fifth awkward input of your own and note which line of the spec it tests.

Done when

  • The vague prompt scores 0/4 sections.
  • The spec prompt scores 4/4 sections.
  • Every rule in Rules could be checked by reading one reply.

Open in the Playground No API key needed.

Starter code (Python)
import anthropic

client = anthropic.Anthropic()  # simulated key and model: nothing real is called

VAGUE = "You are a world-class expert assistant. Be helpful and careful."

SPEC = {
    "Goal": "Answer billing questions for Payly, a payroll app for firms with 5-50 staff.",
    # TODO: add "Audience": who reads the answers, and how plain the words should be.
    # TODO: add "Rules": what to answer from, what never to promise, what to do when unsure.
    # TODO: add "Output": length and shape of the reply.
}
SECTIONS = ["Goal", "Audience", "Rules", "Output"]

def build(spec):
    return "\n".join(f"{name}: {spec[name]}" for name in SECTIONS if spec.get(name))

def check(prompt):
    found = [s for s in SECTIONS if f"{s}:" in prompt]
    return len(found), [s for s in SECTIONS if s not in found]

for label, prompt in [("Vague prompt", VAGUE), ("Spec prompt", build(SPEC))]:
    score, missing = check(prompt)
    print(f"{label}: {score}/4 sections" + (f" (missing {', '.join(missing)})" if missing else ""))

reply = client.messages.create(
    model="claude-sonnet-5-5", max_tokens=300, system=build(SPEC),
    messages=[{"role": "user", "content": "Can I get a refund for last month?"}],
)
print("Reply:", "".join(b.text for b in reply.content if b.type == "text")[:160])
Show a solution
import anthropic

client = anthropic.Anthropic()  # simulated key and model: nothing real is called

VAGUE = "You are a world-class expert assistant. Be helpful and careful."

SPEC = {
    "Goal": "Answer billing questions for Payly, a payroll app for firms with 5-50 staff.",
    "Audience": "Office managers, not accountants. Plain words, no jargon.",
    "Rules": "- Only answer from the help-centre articles provided.\n- Never promise refunds; route refund requests to a person.\n- If unsure, say so and offer to connect them with support.",
    "Output": "2-4 short paragraphs. End with the title of the article you used.",
}
SECTIONS = ["Goal", "Audience", "Rules", "Output"]

def build(spec):
    return "\n".join(f"{name}: {spec[name]}" for name in SECTIONS if spec.get(name))

def check(prompt):
    found = [s for s in SECTIONS if f"{s}:" in prompt]
    return len(found), [s for s in SECTIONS if s not in found]

for label, prompt in [("Vague prompt", VAGUE), ("Spec prompt", build(SPEC))]:
    score, missing = check(prompt)
    print(f"{label}: {score}/4 sections" + (f" (missing {', '.join(missing)})" if missing else ""))

reply = client.messages.create(
    model="claude-sonnet-5-5", max_tokens=300, system=build(SPEC),
    messages=[{"role": "user", "content": "Can I get a refund for last month?"}],
)
print("Reply:", "".join(b.text for b in reply.content if b.type == "text")[:160])
Quick checkWhich system prompt opening gives Claude the most to work with?
How sure are you?
Pick an answer and how sure you are