Claude: XML & Prefilling
Pre-Flight Briefing
Speaking Claude's Language
Anthropic's Claude 3 family (Haiku, Sonnet, Opus) is heavily fine-tuned to recognize and obey XML tags. Using tags like <context>, <instructions>, and <input> creates a rigid hierarchy that prevents Claude from getting confused or being susceptible to prompt injection.
A best practice for Claude is to put your long documents inside tags at the top, and your actual instructions at the very bottom.
Claude also supports a uniquely powerful feature: 'Prefilling'. Because Claude acts as an auto-complete engine, you can dictate exactly how it starts its response by ending your prompt with the opening tag of the format you want (e.g., ending with '{' to force JSON).
Reference Examples
Response Prefilling (Forcing JSON)
Analyze the data and output it as JSON.
{