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