Prompt Delimiters and Tags
Level 2 · Writing a better prompt
How tags and other delimiters keep your instructions apart from the text the model works on. Where to put each part, and what a tag cannot stop.
Course contentsLesson 4 of 16
Level 1 · What a prompt is
Level 2 · Writing a better prompt
Level 3 · Harder and bigger tasks
Level 4 · Prompts inside an app
After this lesson you can
- Fence off pasted text with named tags
- Order a long prompt so the question comes last
- Explain why tags do not stop prompt injection
10 mincovers 2 glossary entries
Worth reading first: System Prompts and Roles
How tags keep the parts of a prompt apart
A prompt delimiter is a mark that fences off one part of a prompt from another. Triple quotes, lines of hash marks and tags such as <email> and </email> all work. They tell the model where your instructions end and where the text it should work on begins.
This matters most when you paste in something long or written by someone else. A three-page contract, an email or a web page can all hold lines that sound like orders. Inside a fence, the model is far more likely to treat them as text to work on.
Tags are the most common choice with chat models. Give each one a plain name that says what it holds: contract, notes, question. Use the same names every time, and close every tag you open. Then you can point at a part by name, such as sum up the text in the contract tags.
Order helps too. Put long documents near the top and your question at the end. Models tend to use the start and the end of a long input best. A question asked after the text it is about is often answered better than one asked before it.
Tags work on the way out as well. Ask for the answer inside answer tags, and your code can cut out exactly that part. Ask for notes in one tag and the answer in another, and you can keep the notes for yourself and show only the answer.
A fence helps the model, but it is not a lock. A clever line inside the fenced text can still steer the model. That trick is called prompt injection. A fence lowers the risk. Limiting what the app is allowed to do is what keeps the damage small.
Do not overbuild it. A one-line question needs no tags. Tags pay off once a prompt has two or more parts that could be mixed up: rules and data, examples and the real task, or two documents to compare.
<email>
Hi team, the launch moves from 3 June to 10 June.
Please send your slides by 6 June.
</email>
Sum up the email in the email tags in two sentences.
Then list every date it mentions.Worked example
Jack sums up customer emails
Jack's tool sums up customer emails. One test email ends with a line telling the model to reply in French. With no tags, 4 of his 20 test summaries come back in French.
He puts each email inside email tags and moves his request below them. Only 1 of the 20 goes wrong now. He also makes sure the tool cannot send any email on its own.
The words for this lesson2
Check yourself
Do tags around pasted text stop prompt injection?
Finished this lesson?
Marking it complete also marks its 2 glossary entries learned, which updates your roadmap and your saved page. 0 are already marked.