Advanced System Prompt Design: XML Tagging, Delimiters & Reasoning Scaffolds
How to structure system instructions that eliminate drift, prevent prompt injection, and yield deterministic output schemas.
Prerequisites
- Basic familiarity with LLM chat interfaces
Step 1: Step 1: Enclose Untrusted User Input in Semantic Tags
Models can be steered by malicious user prompts if they blend with instructions. Always wrap context and user input inside explicit XML boundaries.
Step 2: Step 2: Specify Thinking Protocols and Output Schemas
Instruct the model to emit its internal analysis within <scratchpad> tags before delivering the final response inside <response> JSON tags.