XML Tags & Delimiters
Use structured formatting to clearly separate instructions from content
What is XML Tags & Delimiters?
XML tags and delimiters are a structured way to organize your prompts by separating different components into distinct sections. Using tags like <instruction>, <context>, and <input> helps the AI understand exactly what each part of your prompt is supposed to do.
This technique is especially powerful with LLMs trained on code or XML-like structures, as they recognize these patterns as explicit boundaries.
When to Use It
Best For:
- • Long, complex prompts
- • Multi-part tasks
- • Document processing
- • Code generation tasks
Not Ideal For:
- • Simple, one-line queries
- • Quick questions
- • Casual conversations
- • Time-sensitive tasks
Examples
def get_user(id): return db.query(id)
Best Practices
- 01 Use consistent tag names
Stick to standard tags like <instruction>, <context>, <input>, <output>
- 02 Close all tags
Always use closing tags (</tag>) to maintain proper structure
- 03 Nest logically
Group related content under parent tags for clarity
- 04 Add comments for complex prompts
Use <!-- comments --> to explain sections to future readers
XML Tags vs Plain Text
While plain text prompts work for simple tasks, XML tags provide clarity for complex prompts. They help the model distinguish between instructions and content, reducing confusion and improving output quality. This becomes especially important when building AI applications or chains.