Anthropic Prompt Engineering Guide — Official Best Practices
Official prompting guide from Anthropic for Claude. System prompts, chain-of-thought, few-shot, XML tags, tool use, and advanced techniques.
What it is
This is Anthropic's official prompt engineering guide for Claude models. It covers system prompts, chain-of-thought reasoning, few-shot examples, XML tag structuring, tool use, and advanced techniques for getting reliable outputs from Claude. The guide represents Anthropic's own recommendations based on internal research and user feedback.
This resource is essential for developers building applications with Claude, prompt engineers optimizing performance, and anyone who wants to get better results from Claude models.
How it saves time or tokens
Good prompts reduce iteration cycles. Instead of trial-and-error, this guide teaches proven patterns that work on the first try. Techniques like XML tag structuring reduce ambiguity, which means fewer retries and lower token costs. Chain-of-thought prompting improves accuracy on complex tasks, reducing the need for human correction. The estimated token cost to study and apply the guide is around 500 tokens per session.
How to use
- Read the guide sections relevant to your use case.
- Apply the recommended prompt structure to your system prompts.
- Use XML tags to organize complex instructions.
- Test and iterate with the techniques described.
<!-- Recommended Claude prompt structure -->
<system>
You are a senior code reviewer. Analyze the provided code
for bugs, security issues, and performance problems.
<rules>
- Focus on logic errors, not style
- Rate severity as HIGH, MEDIUM, or LOW
- Provide a fix for each issue found
</rules>
<output_format>
Return a JSON array of issues:
[{"line": N, "severity": "...", "issue": "...", "fix": "..."}]
</output_format>
</system>
Example
Applying chain-of-thought with XML tags:
<instructions>
Analyze this SQL query for performance issues.
Think step by step:
1. Identify the tables and joins involved
2. Check for missing indexes based on WHERE clauses
3. Look for N+1 query patterns
4. Suggest specific optimizations
Put your reasoning in <thinking> tags before the final answer.
</instructions>
<query>
SELECT u.name, COUNT(o.id) as order_count
FROM users u
LEFT JOIN orders o ON u.id = o.user_id
WHERE o.created_at > '2026-01-01'
GROUP BY u.name
ORDER BY order_count DESC
</query>
Related on TokRepo
- Prompt library — Curated prompts and templates
- AI coding tools — Tools for AI-assisted development
Common pitfalls
- Overly long system prompts waste tokens and can dilute important instructions. Keep system prompts focused.
- Few-shot examples that do not match the target format cause inconsistent outputs. Ensure examples closely mirror expected input.
- Chain-of-thought prompting increases output tokens. Use it for complex reasoning tasks, not simple lookups.
- XML tags help Claude parse structure but are not required for simple tasks. Do not over-structure simple prompts.
- The guide evolves as Claude models improve. Techniques optimal for Claude 3 may need adjustment for newer models.
Frequently Asked Questions
XML tags like <instructions>, <context>, and <output_format> help Claude parse different sections of a prompt. They reduce ambiguity and improve instruction following, especially in complex prompts with multiple sections.
Use chain-of-thought for tasks requiring multi-step reasoning: math problems, code analysis, logical deduction, and complex decision-making. For simple tasks like translation or formatting, direct prompting is more efficient.
Few-shot examples show Claude the exact input-output format you expect. They are especially useful for structured outputs, specific formatting requirements, or domain-specific terminology. Two to three examples usually suffice.
The core techniques apply across Claude models. However, newer models like Claude Sonnet 4 handle ambiguity better than older versions, so some techniques may be more or less critical depending on the model.
Define tools with clear descriptions, parameter types, and expected behavior. Claude uses tool descriptions to decide when and how to call tools. Specific, unambiguous tool descriptions lead to more accurate tool selection.
Citations (3)
- Anthropic Documentation— Anthropic official prompt engineering guide
- Anthropic Claude Docs— Claude model capabilities and best practices
- Anthropic Tool Use Docs— Tool use with Claude
Related on TokRepo
Source & Thanks
Created by Anthropic. Anthropic Documentation