A prompt delimiter is a marker that separates distinct parts of a prompt, such as instructions, reference documents, examples and user input, so that a language model can tell where each part begins and ends. In prompting, common delimiters include XML tags in prompts, triple quotes, triple backticks, Markdown headings and lines of repeated symbols.
Delimiters matter because a model receives the prompt as one continuous token sequence. Without clear boundaries, the model may treat a quoted email as an instruction, mix an example with the real task or answer about the wrong document. A well-chosen delimiter turns a flat stream of text into a structured input that the model can follow reliably.
How prompt delimiters guide a language model
Prompt delimiters work because large language models learn structural conventions from their training data, where code blocks, quoted passages, markup and section headings consistently mark changes in content type. When a prompt reuses these conventions, the model applies the same learned boundary behavior and keeps the enclosed text in its intended role.
Delimiters perform three related jobs. They mark scope, so that an instruction such as summarize the text applies to exactly one block. They assign roles, distinguishing material the model should read from commands it should obey. They also create named references, letting the instruction mention a specific block by its label, for example the contract tag or the second example.
Delimiters are not a parsing mechanism inside the model. They raise the probability of correct interpretation but do not enforce it, which is why they reduce rather than eliminate errors such as instruction confusion.
Types of prompt delimiters
The main delimiter families differ in how clearly they label content and how likely they are to collide with the text they enclose. The following table compares the forms most often used in practice.
| Delimiter style | Example form | Strength | Weakness |
|---|---|---|---|
| XML-style tags | Named opening and closing tags | Self-describing names, easy nesting | Slightly more tokens |
| Triple quotes | """ around a passage | Short and familiar | No label, collides with quoted text |
| Triple backticks | Fenced block with three backticks | Clear for code and data | Clashes with code containing fences |
| Markdown headings | ## Context before a section | Readable for humans | End of section is implicit |
| Separator lines | ### or --- between parts | Minimal overhead | No names, weak with long inputs |
XML tags in prompts have become a widely recommended default for complex prompts because each block carries a descriptive name and an explicit closing marker. Some model providers state in their prompting guidance that their models were trained to attend closely to such tags, although the tag names themselves have no predefined meaning and can be chosen freely.
Choosing and naming delimiters
The right delimiter depends on prompt length, content type and how the output will be processed. Short prompts with one data block work well with triple quotes, while long prompts with several documents, examples and rules benefit from named, nested tags.
The decision table below maps typical situations to a recommended choice.
| Situation | Recommended delimiter | Reason |
|---|---|---|
| Single short passage | Triple quotes | Low overhead, clear enough |
| Several documents | Tags with an index attribute or number | Each document stays addressable |
| Source code as input | Tags rather than backtick fences | Avoids collision with fences in the code |
| Few-shot examples | One tag per example inside an examples tag | Keeps examples apart from the task |
| Machine-parsed output | Tags requested in the answer | Easy extraction with a simple parser |
Good practice is to use names that describe the content, such as contract, customer email or style guide, and to refer to those names in the instruction itself. Consistency matters more than the specific style: mixing quotes, fences and tags for similar content within one prompt weakens the boundaries the model relies on.
Delimiters in prompt structure and output control
Delimiters shape both the input structure and the output format, and they connect naturally with neighboring techniques such as the prompt template, output format instruction and response prefilling. In a prompt template, delimited slots mark where variable content is inserted, which keeps the fixed instructions stable across calls.
- Long-context prompts: placing large documents in tags near the top and the question at the end tends to improve answer quality.
- Reasoning separation: asking the model to think inside one tag and answer inside another lets an application show only the final answer.
- Structured extraction: requesting each field in its own tag gives output that a short script can parse.
- Prefilled responses: starting the reply with an opening tag commits the model to the expected format from the first token.
For output that must be strictly machine-readable, delimiters are a lightweight option, but JSON schemas or structured output features offer stronger guarantees when the platform supports them.
Prompt delimiters and prompt injection
Delimiters are a partial defense against prompt injection, the attack in which untrusted text contains instructions that try to override the original task. Wrapping user content in tags and stating that the enclosed text is data, not instructions, measurably lowers the success rate of naive attacks.
The protection is limited because an attacker can insert a fake closing tag and continue with new commands, and because models can still follow persuasive instructions inside the data block. Serious applications therefore combine delimiters with input sanitization, privilege separation and output validation.
| Pitfall | Consequence | Remedy |
|---|---|---|
| Delimiter appears in the data | Block ends too early | Escape the marker or choose a rarer one |
| Unclosed tag | Model misreads where content stops | Generate prompts from a checked template |
| Vague tag names | Instructions refer to the wrong block | Use descriptive, unique names |
| Trusting delimiters for security | Injection succeeds with fake tags | Add sanitization and least privilege |
In simple terms
Imagine handing a colleague a stack of papers with a sticky note on top. If the note and the papers are all mixed together, the colleague may confuse your request with a sentence in one of the documents. Prompt delimiters are like labeled folders: one folder holds your instructions, another holds the letter to read, a third holds examples.
An AI model reads everything as one long text, so these labels show it what each part is for. Clear labels lead to fewer mix-ups and answers that address exactly what was asked.
A practical example
A legal operations team builds an internal assistant that compares supplier contracts against the company policy on liability caps. Early versions pasted the policy and the contract one after another, and the model sometimes quoted policy text as if it were a contract clause.
The team rewrites the template so that the policy sits inside a tag named policy, each contract inside a tag named contract with a numeric index, and the answer must list each finding inside a tag named finding. They also add the sentence that text inside the contract tags is material to analyze, not instructions. In a test on 200 contracts, misattributed quotations dropped from 23 cases to 2, and the findings could be extracted automatically into the review spreadsheet without manual copying.