intermediateChapter 4 of 12
Separating Data from Instructions
XML tags as delimiters · Variable substitution · Data/instruction separation
Why Separation Matters
When your prompt mixes instructions and data, Claude can confuse one for the other — especially with longer inputs. XML tags cleanly delineate what's data and what's an instruction.
XML Tags in Prompts
Claude was trained to recognize XML tags as a prompt-organizing mechanism. Use descriptive tag names:
Summarize the following article in two sentences.
<article>
Climate change is accelerating at an unprecedented rate...
</article>
Variable Substitution
In production, you often reuse the same prompt template with different data. Use placeholders like {VARIABLE} inside tags:
Translate the following text from {SOURCE_LANGUAGE} to {TARGET_LANGUAGE}.
<text>
{INPUT_TEXT}
</text>
Key Takeaways
- Use XML tags (
<document>,<text>,<email>,<data>) to separate data from instructions. - Place the instruction outside the data tags.
- Variable placeholders + XML tags = reusable prompt templates for production systems.
Exercises
12
XML Tag Separation
Rewrite a prompt that mixes instructions and data into one that uses XML tags to cleanly separate them.
Variable Substitution with XML Tags
Create a prompt template that uses variable placeholders inside XML tags, allowing you to swap in different data while keeping the instruction constant.