How do delimiters and tags make prompts clearer?

Asked 17 hours ago Updated 17 hours ago 29 views

1 Answer


0

When a prompt contains both instructions and content, such as an email to rewrite, a document to summarise or data to analyse, the AI can sometimes confuse the two. Delimiters solve this by clearly marking where each part begins and ends.

A delimiter is any clear marker that separates sections of a prompt. Common options include:

1. Labelled headings: "Instructions:", "Document:", "Example:".
2. Triple quotes or triple backticks around text.
3. Dashes or lines: "---".
4. XML-style tags: <document> ... </document>, <instructions> ... </instructions>.

Here is an example without delimiters:

"Summarise this and make it formal. Hi team, the meeting moved to Friday, please bring the sales figures and don't forget to check the new rules."

The AI might be unsure where your instructions end and the content begins.

With delimiters:

"Summarise the email below in two formal sentences.

<email>
Hi team, the meeting moved to Friday, please bring the sales figures and don't forget to check the new rules.
</email>"

Now the boundaries are clear.

Why use XML-style tags? They are especially effective with many AI models, and Anthropic's guidance for Claude has long recommended them. They let you name each section meaningfully and refer to it in instructions: "Answer using only the information in <policy>, and write in the style of <example>."

Delimiters are especially useful when:

1. Pasting long documents along with questions.
2. Providing several documents to compare: <document1>, <document2>.
3. Including examples that should not be confused with the task.
4. Giving content that itself contains instructions, such as an email saying "please reply by Friday," which the AI might otherwise treat as an instruction to itself.
5. Building prompts for apps, where user input should be clearly separated from your system instructions.

That last point also relates to security. When user input or external content is clearly marked as data, it is somewhat harder for hidden instructions inside that content to hijack the AI's behaviour. Delimiters alone are not a complete defence against prompt injection, but they help.

Tips:

Use consistent tag names.
Close every tag.
Refer to tags by name in your instructions.
Put long content first and your question or instructions after it.

Delimiters take seconds to add and make complex prompts noticeably more reliable.

Write Your Answer