Structuring Prompts with XML Tags
When a prompt combines system instructions, retrieved documents, user input, and few-shot examples, plain prose quickly blurs boundaries. Wrapping each logical section in descriptive XML tags lets the model parse intent cleanly and reduces prompt-injection risk.
Recommended Section Layout
<role>
You are a senior backend reviewer focused on correctness and security.
</role>
<context>
{{diff_or_document}}
</context>
<rules>
- Cite exact line numbers for every issue.
- Separate blocking defects from optional style suggestions.
- If no defects exist, say so concisely.
</rules>
Why It Works in Long Contexts
Long-context retrieval degrades when instructions sit between large blocks of raw text. Placing static rules in the system prompt, putting variable reference material inside <documents>, and repeating the exact deliverable format at the end keeps recall high even above 100k tokens.
Checklist Before Shipping
- Keep tag names consistent across prompts and evaluation harnesses.
- Avoid nesting more than two levels deep unless parsing machine output.
- Pair XML input framing with strict JSON schema validation when downstream code consumes the reply.