Study guides / CCAO-F / Domain 1

Prompting and Task Execution · Lesson 3 of 5

1.3 — Structuring Prompts with XML Tags

Use XML-style tags to separate context, instructions, examples, and input so Claude doesn't confuse one part of a prompt for another.

Claude is trained to recognise XML-style tags like <context>, <instructions>, <examples>, and <input>. When a prompt mixes background context, formatting instructions, worked examples, and the actual thing to process into one wall of unlabeled text, Claude can lose track of which part is which — most commonly, it can mistake a worked example for the actual input it's supposed to act on.

This becomes more important, not less, as task-execution prompts get longer and more composite: a request that decomposes into background, rules, a couple of examples, and a live query is exactly the shape where structure earns its keep.

A Concrete Failure Mode

Imagine a prompt that has background context, formatting rules, two worked examples, and the real customer message, all as unlabeled paragraphs in sequence. Claude may respond to the second worked example as if it were the real customer's message, because nothing in the prompt marks the boundary between "here's an example of what to do" and "here's the actual task."

The fix is to wrap each distinct part in its own tag:

<context>
You're responding to messages in the #support channel.
</context>

<examples>
<example>...</example>
<example>...</example>
</examples>

<input>
Hi, my order #4432 hasn't shipped yet.
</input>

Now there's no ambiguity: anything inside <input> is the live request, and anything inside <examples> is reference material, not something to respond to directly.

Tags Are Free-Form, Not a Fixed Set

There's no required list of tag names — <context>, <instructions>, <examples>, and <input> are conventions, not a strict schema. Use whatever tag names make the structure of your specific prompt obvious: <background>, <constraints>, <document>, <question> all work fine. The value comes from consistent, unambiguous separation, not from matching an exact vocabulary.

Key Concept

Tagging each distinct part of a multi-part prompt — context, instructions, examples, input — is Anthropic's recommended way to structure longer prompts. It removes ambiguity about where one section ends and the next begins.

Common Exam Distractor

A prompt that mixes context, instructions, and a variable user query as unlabeled paragraphs, where Claude sometimes treats an example as real input, points to one fix: wrap each part in its own XML tag. Don't be pulled toward answers about rewording the instructions themselves — the problem is structural, not about word choice.

Exam traps

Practice question

A prompt mixes background context, formatting instructions, a couple of worked examples, and a variable user query, all as unlabeled paragraphs. Claude sometimes treats one of the worked examples as if it were the actual request to respond to. What change would most directly fix this?

  • A Wrap each distinct part — context, instructions, examples, and the actual query — in its own XML tag Correct

    Tagging each section removes the structural ambiguity that causes Claude to confuse an example with the live request.

  • B Move the worked examples to the very end of the prompt, after the user's query

    Reordering without tagging doesn't remove the ambiguity — Claude still has no explicit marker for which text is an example versus the real input.

  • C Shorten the worked examples so they take up less of the prompt

    Length isn't the cause of the confusion; the lack of a clear boundary between sections is.

  • D Repeat the user's query twice, once near the top and once at the bottom of the prompt

    Duplicating the query without labelling sections doesn't resolve which part of the prompt is an example versus the actual task.

Build exercise: Diagnose and Fix a Tag-Confusion Prompt

Beginner · 20 minutes

You'll practice:

  1. In a claude.ai conversation, write a single unlabeled prompt that includes a sentence of context, two short worked examples of a task (e.g. classifying a sentence as 'positive' or 'negative'), and then a real sentence to classify — all as plain paragraphs with no tags or headers.

    This reproduces the failure mode the exam tests: without structure, Claude may respond to an example instead of the real input.

    You should see: A response that addresses one of your worked examples, or blends the example and the real input together, rather than cleanly classifying only the final sentence.

    Hints
    1. Make the worked examples look plausible as 'real' input — don't visually distinguish them beyond word choice.
    2. Include at least two examples so there's a clear boundary that could get confused with the real query.
    3. If Claude gets it right anyway, add a third distractor example to increase the chance of confusion.
  2. Rewrite the same prompt using <context>, <examples>, and <input> tags to clearly separate each part, then resend the same real sentence.

    This applies the documented fix and lets you directly compare behaviour with and without structure.

    You should see: A clean response addressing only the sentence inside <input>, with no reference to the worked examples as if they were the task.

    Hints
    1. Wrap each individual example inside its own <example> tag, nested inside a single <examples> block.
    2. Put the real sentence to classify inside <input> tags, clearly separate from the examples.
    3. Compare this response directly against the unlabeled version to confirm the improvement.
  3. Try renaming your tags to something non-standard but still descriptive, like <background> and <task>, and confirm the structure still resolves the ambiguity.

    This checks the exam trap that tag names must match a fixed official vocabulary — they don't; consistent labeling is what matters.

    You should see: The same clean, unambiguous response as with the conventional tag names.

    Hints
    1. Keep opening and closing tag names matched exactly.
    2. The content and clarity of separation matters more than the specific word you choose.
    3. Note in one sentence why this confirms tags are a convention, not a strict schema.

Sources