PaPoo
cover

What is using XML tags / delimiters in prompts?

Using XML tags or other delimiters in prompts means wrapping parts of your prompt in clear markers like <context>...</context> so the model can separate instructions, data, and examples more reliably.

Why it matters

This pattern helps when a prompt contains multiple kinds of content at once: instructions, source text, user input, examples, or fields you want the model to treat differently. Delimiters reduce ambiguity and make prompts easier to read, debug, and reuse.

In practice, teams reach for XML-style tags when they want:

It is not magic, and it is not a formal XML parser contract. It is simply a formatting convention that many LLMs handle well because the structure is explicit.

How it works

You choose a set of tags or delimiters and assign each section a role. For example, you might put instructions in <instructions>, source material in <document>, and the user query in <question>.

The model then sees the prompt as structured text. This can make it less likely to confuse quoted data with instructions, especially when the input includes long passages, code, or nested examples.

A common pattern is:

  1. Put high-level instructions first.
  2. Wrap untrusted or variable content in tags.
  3. Ask the model to respond in a specific format, sometimes also tagged.

This is closely related to delimiter-based prompting in general. XML tags are just one readable delimiter style.

Tiny concrete example

<instructions>
Answer using only the document.
</instructions>

<document>
Acme ships every Friday and supports returns within 30 days.
</document>

<question>
When does Acme ship?
</question>

A model can more easily infer that the answer should come from <document>, not from the instruction block.

Common pitfalls / when NOT to use it

In practice, most teams use delimiters for clarity first, and only later add stricter schemas if they need reliable machine parsing.

Related terms

同じ著者の記事