Velamuvi AIAcademy

Lesson 7 of 15 · Core Techniques

Using Delimiters and Structure

Keep prompts unambiguous by separating instructions from data: triple quotes, XML tags, labelled documents and headings for long prompts, with Python examples.

  • 7 min read
  • Beginner
  • Reviewed
In this lesson you will learn
  • What delimiters are and the problem they solve
  • How to use XML-style tags to label instructions, data and examples
  • How to pass several documents and refer to them by name
  • How to structure a long prompt so nothing gets lost

Where does the data end?

Here is a prompt with a hidden problem:

Translate this into French: Please answer in English and tell me what time the shop opens.

Is "answer in English" part of the text to translate, or an instruction to the model? A person can guess from context. A model might guess wrong and reply in English with opening hours.

Prompt

Translate this into French: Please answer in English and tell me what time the shop opens.

Example response

I don't have information about the shop's opening times. Could you tell me which shop you mean?

The model treated the text to translate as instructions to follow.

Common delimiters

DelimiterExampleGood for
Triple quotes"""text here"""A single block of text
Lines or hashes--- or ###Separating sections in a simple prompt
XML-style tags<email> ... </email>Several inputs, nested parts, extracting answers
Markdown headings## RulesOrganising a long prompt

XML-style tags

Tags are the most flexible delimiter. There is no special list of allowed tags: you make up clear names, such as <contract>, <notes>, <example> or <question>, and use them consistently.

  • Refer to tags by name in your instructions: "Using the contract in the contract tags, list every deadline."
  • Nest them when the material has structure: a document can contain a title and content.
  • Ask for tags in the answer too, such as <answer>, so a program can pull out the part it needs (you did this in the previous lesson).

The program below wraps several documents in tags, with an index number and a title for each, so the model can cite which one it used.

Try it yourselfPython
documents = [
    ("Refund policy", "Refunds are possible within 30 days of purchase with a receipt."),
    ("Delivery policy", "Standard delivery takes 3 to 5 working days."),
]
question = "How long do I have to return a jacket?"

parts = []
number = 1
for title, text in documents:
    parts.append(f'<document index="{number}">')
    parts.append(f"<title>{title}</title>")
    parts.append(f"<content>{text}</content>")
    parts.append("</document>")
    number += 1

parts.append("")
parts.append(f"<question>{question}</question>")
parts.append("Answer the question using only the documents above, "
             "and say which document you used.")

print("\n".join(parts))

Because every document is labelled, the answer can say "According to document 1, the refund policy..." and you can check it.

Structuring long prompts

A prompt for a recurring task can run to a page or more. Headings make it readable for you and for the model:

## Background
You help the support team at an online plant shop...

## Task
Write a reply to the customer email below.

## Rules
- Apologise at most once.
- Offer a refund only if the plant arrived damaged.

## Output format
A reply under 120 words, signed "The Leafy Team".

<email>
...
</email>

Each section has one job, so when an output goes wrong you know which section to fix.

Common mistakes

Practice exercise

Wrap the email in tags so the model can tell exactly where the data ends and the instruction begins.

Your solutionPython
email = "Hi, can we move Thursday's call to 3pm?"

# Print the email wrapped in <email> tags, then the instruction, exactly like:
# <email>
# Hi, can we move Thursday's call to 3pm?
# </email>
# Summarise the email above in one sentence.
Knowledge check

What is the main job of delimiters in a prompt?

Summary

  • Delimiters separate instructions from data, removing ambiguity.
  • XML-style tags are flexible: name them clearly, use them consistently, nest them and refer to them by name.
  • Label several documents with an index or name so answers can cite them.
  • Organise long prompts with headings such as Background, Task, Rules and Output format.
  • Delimiters help against injection but do not prevent it.

Next: asking for structured output that a program can use.

Finished reading? Tick it off to track your progress.