Part 15 / Topic 2 of 6
Structure with XML tags
When a prompt mixes instructions, reference documents and user input, mark the boundaries — XML-style tags are the convention Claude is trained to respect:
# examples/01_a_clear_prompt_role_xml_tagged.py (output, abridged)
You answer customer questions for an online store.
Use only the documents below. If they do not contain the answer, say you don't know.
Cite the doc id in square brackets after each fact.
<documents>
<doc id="payment">We accept credit and debit cards, UPI and cash on delivery. ...</doc>
</documents>
<examples>
<example><q>How fast is express shipping?</q><a>Express shipping takes 1 to 2 business days [shipping].</a></example>
</examples>
<question>Can I pay cash on delivery for a 12,000 order?</question>
Three habits in one prompt: instructions first; data fenced in <documents>; the grounding rules ("use only", "say you don't know", "cite ids") stated explicitly. This exact shape returns as the RAG prompt in Part 17.
🧪 Quick quiz
- Why wrap documents in tags such as
<documents>?
Show the answer
It clearly separates instructions from data, so the model knows which is which — reducing confusion between your rules and the content you pass in.
Done here? The practice set for Part 15 — 4 exercises with solutions — is on the part page.