How to structure a prompt for Claude
A prompt is a spec. Five parts in order (role, task, context, examples, output format), tagged with XML, kept in git and tested like code.

This is Day 4 of Claude Architect in 30 Days. Day 3 was about choosing the model. Today is about what you tell it. A prompt that works in a demo often fails in production for one reason: it was written as a wish, not a specification.
Who this is for: anyone writing or maintaining prompts for a feature that real users depend on, technical or not.
Start with the teammate test
Imagine handing your prompt to a capable new colleague who knows nothing about your product. Could they do the task from it alone? If they would need to ask what tone to use, which policy applies, or what to do when the answer isn't known, Claude has the same gaps and fills them by guessing. Guesses vary from run to run, and that variation is what shows up later as bugs nobody can reproduce.
The five parts
- Role: who Claude is in this job. This goes in the system prompt: "You answer customer questions for an online furniture shop."
- Task: what to do with this request, stated plainly.
- Context: the material it needs: a policy, a document, the customer's order.
- Examples: two or three real inputs with the output you want.
- Output format: exactly what to return and how it should look.
Put together, the user turn of a support prompt might look like this:
<policy>
...the refund policy text...
</policy>
<examples>
<example>
<question>Can I return a sofa after 40 days?</question>
<answer>Our return window is 30 days, so...</answer>
</example>
</examples>
<instructions>
Answer using only the policy above. If the policy doesn't cover
the question, say so and offer to connect the customer with a person.
Replies are read on a phone, so keep them under 80 words.
</instructions>
<question>Can I return an opened item?</question>Say why, not just what
"Keep replies under 80 words because they're read on a phone" works better than "BE BRIEF". With the reason, Claude can make sensible calls in cases the rule didn't anticipate. Anthropic's guidance for its newer models also warns that shouting, in capitals or with words like MUST, tends to make a model apply a rule too eagerly, in places it was never meant for.
Tag the parts with XML
Tags such as <policy>, <examples> and <instructions> let Claude tell your rules apart from your data. That matters most when the data contains text that looks like instructions, which customer messages and web pages often do. The tag names don't have to be special words; they only have to be consistent.
Examples: show, and vary them
One good example does more than a paragraph of description. Use two or three, and make them different from each other in the ways real inputs differ. If every example is a short, polite question, Claude will treat a long, angry one as unfamiliar territory.
Long documents first, question last
When the prompt includes long material, put it near the top and the question or task at the end. Anthropic's long-context guidance recommends this order, and it also suits prompt caching (Day 7 of the series), because the unchanging part comes first.
Keep prompts in git
A prompt is code that happens to be written in English. It belongs in version control, with changes reviewed and tested against your eval set before they ship. Prompt versioning covers why editing prompts by hand in a settings screen goes wrong.
Try this today
Rewrite one of your prompts using the five parts. Then run the old and new versions on ten real inputs and compare the answers side by side. Tomorrow, Day 5 covers getting JSON from Claude that your code can trust. If your team's prompts have grown hard to change safely, that's the kind of problem I help with in AI agents and automation.
Prefer slides? Download today's carousel as a PDF.