How to Write Prompts for Claude: 6 Core Principles from the Official Docs

Six practical prompting principles distilled from Anthropic's official documentation — clarity, context, examples, XML structure, roles, and long-context handling.

Good answers start with good prompts. What you ask Claude — and how — dramatically affects the quality of the result. This guide distills Anthropic's official prompt engineering documentation into six practical principles you can apply right away, even if you don't write code.

6 prompting principles (official) 1 Be clear & direct 2 Add context 3 Use examples 4 XML tags 5 Give a role 6 Long context Source: Anthropic prompt engineering docs. Works across model versions.

Why prompting matters

Anthropic's docs compare Claude to "a brilliant but new employee who has zero context" on your project. However capable, it can't read your mind about goals, norms, or preferences. The clearer you are, the better it performs. The docs also note that prompt engineering is faster and cheaper than fine-tuning, keeps everything human-readable, and works across model updates without retraining.

Six core principles (official)

1. Be clear and direct

Claude responds well to explicit, specific instructions. State the desired output format and constraints, and use numbered lists when step order matters. The official golden rule: "Show your prompt to a colleague with minimal context and ask them to follow it. If they'd be confused, Claude will be too."

  • Less effective: "Create an analytics dashboard"
  • More effective: "Create an analytics dashboard. Include as many relevant features and interactions as possible. Go beyond the basics to create a fully-featured implementation."

2. Add context

Explaining the reason or motivation behind an instruction helps Claude understand your goal and respond more precisely.

  • Less effective: "NEVER use ellipses"
  • More effective: "Your response will be read aloud by a text-to-speech engine, so never use ellipses since it won't know how to pronounce them."

Claude generalizes from the explanation to handle similar cases.

3. Use examples

Examples are one of the most reliable ways to steer output format, tone, and structure. A few well-crafted examples (few-shot / multishot) sharply improve accuracy and consistency. The docs recommend examples that are:

  • Relevant: mirror your actual use case
  • Diverse: cover edge cases so Claude doesn't pick up unintended patterns
  • Structured: wrap them in <example> tags (multiple in <examples>)

The official suggestion is 3–5 examples. You can also ask Claude to evaluate or generate examples for you.

4. Structure with XML tags

When a prompt mixes instructions, context, examples, and inputs, wrapping each in its own tag (e.g. <instructions>, <context>, <input>) lets Claude parse it unambiguously.

  • Use consistent, descriptive tag names.
  • Nest tags when content has a natural hierarchy (e.g. each <document> inside <documents>).

5. Give Claude a role

Setting a role in the system prompt focuses Claude's behavior and tone. Even one sentence helps — e.g. "You are a helpful coding assistant specializing in Python." It's set via the API system parameter, but stating a role up front in normal chat has a similar effect.

6. Long context

For large documents or data (20k+ tokens), the docs recommend:

  • Put longform data at the top, above your query and instructions. In tests, putting the query at the end improved response quality by up to 30% on complex multi-document inputs.
  • Structure documents with XML tags — wrap each in <document> with <document_content> and <source> subtags.
  • Ground responses in quotes — ask Claude to quote relevant passages first, which cuts through document noise.

Practical tips

  • Start small, iterate: Once a prompt works, trim redundant phrasing to make it shorter and cheaper without losing performance.
  • Ask for action explicitly: If you want changes made rather than suggested, say "Make these edits," not "Can you suggest changes?"
  • Use Console tools: The Claude Console offers a prompt generator, templates/variables, and a prompt improver.

Summary

Clarity, context, examples, XML structure, roles, and long-context handling — these six fundamentals hold up across model versions. Rather than writing the perfect prompt on the first try, apply these principles, test quickly, and refine.

Source: Anthropic official prompt engineering documentation (overview, prompting best practices).

Keep reading

Have a question or want to share how you use Claude?

Join the community to share tips with other users, or explore more guides.