Skip to content
AgenticAIWiki
  1. Learn
  2. Part 2
  3. 11. Explicit criteria, roles and XML tags
  4. 11.6

Lesson 11.6 · 6 of 7 · 5 min read · Reviewed 24 Nov 2026

Delimiters and Markdown structure

By the end, you can

  • Use delimiters and Markdown headings to mark the parts of a long prompt.
  • Choose a delimiter that can't collide with the content it wraps.

XML tagsXML tags: Tags such as <document> or <instructions> used in prompts to separate and label different kinds of content. (lesson 11.4) are one way to mark the parts of a prompt. They belong to a bigger family: delimiters, any marker that says “this part is different”. This lesson covers the others, how to give a long prompt a clear shape with Markdown, and the one failure that catches everyone: the delimiter that appears inside the content.

Common delimiters

Delimiter Looks like Good for
Triple backticks ``` before and after Code and logs
Triple quotes """ before and after Short passages of prose
Dashed or hash lines --- or ### on their own line Separating sections
XML-style tags <report> … </report> Named parts, nesting, several documents
Markdown headings ## Rules The skeleton of a long system prompt

All of them work. What matters is that you pick one style per job, use it consistently, and refer to it by name: “the report between the <report> tags”.

Markdown as a skeleton

A long system promptSystem prompt: Instructions passed in the top-level system field that set the model’s role, rules and context for the whole conversation. is easier to maintain, for you and for the model, when it has headings:

# Role
You review pull requests for a payments service.

## What to flag
- Bugs that give wrong results
- Missing error handling on network calls

## What to skip
- Style and naming

## Output
A Markdown list, one item per issue: file, line, one-sentence reason.

Each heading is a place a teammate can find and change one rule without reading the rest. Headings also help the model see which lines are rules and which are format.

Delimiter collision

A delimiter works only if the content can’t contain it. Suppose you write:

Explain this README:
```
<pasted README>
```

If the README itself contains a code block, its first triple backticks close your wrapper early. Everything after it now looks like loose prompt text, including any line in the README that reads like an instruction. The fixes, from strongest to weakest:

  1. Use a named tag the content won’t contain, such as <readme>. Your code can check that the tag name isn’t in the input, or add a short random suffix (<readme_k3f9>).
  2. Use a longer fence. Markdown allows four or more backticks, and a fence only closes on a run at least as long as the one that opened it.
  3. Escape the content, if your format allows it, so the delimiter can’t appear literally.

Matching the output you want

Models tend to answer in the style they are given. A prompt dense with headings and bullets often gets headings and bullets back. If your app shows plain text, such as an SMS or a voice reply, say so explicitly (“plain sentences, no Markdown”) and write the prompt itself in plainer prose. If it renders Markdown, ask for the exact elements you want: “a heading, then at most five bullets”.

Common mistakes

  • Mixing styles: triple quotes for one document, dashes for the next, tags for the third. Pick one.
  • Never checking the input for the delimiter. One line of code prevents the collision.
  • Asking for Markdown where it won’t render, so users see stray asterisks and hashes.

Key points

  • Delimiters such as triple backticks, triple quotes, lines of dashes or XML tags mark where pasted material starts and ends.
  • Markdown headings give a long system prompt a skeleton that both people and models can navigate.
  • A delimiter fails when the content contains it, so pick one the content can't contain, or use named tags.
  • The style of the prompt nudges the style of the reply: a prompt full of Markdown invites Markdown back.
Hands-on labRuns in the Playground

Pick a delimiter that cannot collide

Choose fences and tag names that the content can't close, so pasted text stays inside its wrapper.

You will have: Two helper functions, fence_for and tag_for, with checks on a README that contains code fences.

Steps

  1. Fill in fence_for: one backtick longer than the longest run in the content, and at least 3.
  2. Fill in tag_for: add a number to the tag name until the content doesn't contain it.
  3. Run it on the README and the notes, and read the fence length and tag name.
  4. Check every fence inside the README is shorter than the wrapper.
  5. Paste a README of your own into the script and wrap it both ways.

Done when

  • The README gets a 4-backtick fence.
  • The notes, which mention a readme tag, get readme_2.
  • The inner-fence check prints True.

Open in the Playground No API key needed.

Starter code (Python)
import re

def fence_for(content):
    # A fence only closes on a run of backticks at least as long as the one that opened it.
    # TODO: find the longest run of backticks in content and return a fence one longer (at least 3).
    return "```"

def tag_for(content, name):
    # Pick a tag name the content doesn't contain, adding a counter if needed.
    # TODO: while "<name" or "</name" appears in content, try name_2, name_3, ...
    return name

def wrap_fence(content):
    f = fence_for(content)
    return f"{f}\n{content}\n{f}"

def wrap_tag(content, name):
    t = tag_for(content, name)
    return f"<{t}>\n{content}\n</{t}>"

README = "# Setup\n```\nnpm install\n```\nThen run the tests."
NOTES = "Meeting notes. We discussed the <readme> file and the </readme> closing tag."

print("fence length for README:", len(fence_for(README)))
print("fence length for plain text:", len(fence_for("no backticks here")))
print("tag for NOTES:", tag_for(NOTES, "readme"))
print("tag for README:", tag_for(README, "readme"))

wrapped = wrap_fence(README)
inner_runs = [len(m) for m in re.findall(r"^`+", README, re.M)]
print("inner fences shorter than wrapper:", all(r < len(fence_for(README)) for r in inner_runs))
print(wrap_tag(NOTES, "readme").splitlines()[0])
Show a solution
import re

def fence_for(content):
    # A fence only closes on a run of backticks at least as long as the one that opened it.
    longest = max((len(m) for m in re.findall(r"`+", content)), default=0)
    return "`" * max(3, longest + 1)

def tag_for(content, name):
    # Pick a tag name the content doesn't contain, adding a counter if needed.
    candidate, n = name, 1
    while f"<{candidate}" in content or f"</{candidate}" in content:
        n += 1
        candidate = f"{name}_{n}"
    return candidate

def wrap_fence(content):
    f = fence_for(content)
    return f"{f}\n{content}\n{f}"

def wrap_tag(content, name):
    t = tag_for(content, name)
    return f"<{t}>\n{content}\n</{t}>"

README = "# Setup\n```\nnpm install\n```\nThen run the tests."
NOTES = "Meeting notes. We discussed the <readme> file and the </readme> closing tag."

print("fence length for README:", len(fence_for(README)))
print("fence length for plain text:", len(fence_for("no backticks here")))
print("tag for NOTES:", tag_for(NOTES, "readme"))
print("tag for README:", tag_for(README, "readme"))

wrapped = wrap_fence(README)
inner_runs = [len(m) for m in re.findall(r"^`+", README, re.M)]
print("inner fences shorter than wrapper:", all(r < len(fence_for(README)) for r in inner_runs))
print(wrap_tag(NOTES, "readme").splitlines()[0])
Quick checkYou wrap user-supplied code in triple backticks, but some inputs are Markdown files that already contain triple backticks. The model starts treating part of the code as instructions. What is the best fix?
How sure are you?
Pick an answer and how sure you are