← ContentsPrompting · intermediate

Few-shot examples

Few-shot prompting (also called multishot prompting) is a technique where you include a small number of carefully crafted input-output examples directly inside your prompt before your actual request. Instead of describing what you want in abstract terms, you show Claude concrete demonstrations — Claude reads the pattern from those examples and applies it to new inputs. This is distinct from zero-shot prompting, where no examples are given, or single-shot prompting, where only one example is provided. The technique works because language models are highly sensitive to demonstrated patterns. Showing Claude two to five examples of the input format, reasoning style, output structure, and tone you expect is generally more reliable than writing lengthy prose instructions. Examples can be wrapped in XML tags (e.g., `<examples>` containing individual `<example>` blocks) so Claude can cleanly distinguish demonstration data from the live task. Few-shot examples are not a special feature you toggle on — they are a prompting technique baked into how you write your prompt. They work across every Claude interface: claude.ai chat, the desktop and mobile apps, the Anthropic API, and Claude Code. Token usage counts toward your normal plan limits, but no extra settings or plan upgrades are required to use the technique.

When you’d use it

  • Sentiment classificationA product team wants Claude to label customer reviews as POSITIVE, NEUTRAL, or NEGATIVE in a consistent, machine-readable format. Providing two or three labeled examples locks in the exact output tokens Claude should produce, eliminating freeform commentary.
  • Structured data extractionA support operations team needs to parse unstructured ticket text into structured fields (customer name, issue type, priority). Few-shot examples show Claude exactly which fields to extract and how to handle edge cases like missing names or ambiguous priority.
  • Brand voice and tone enforcementA content team must produce copy that matches a very specific corporate voice — contractions allowed, no passive voice, sentence length capped at 20 words. Providing three on-brand example rewrites is far more reliable than writing a style guide in prose.
  • Code review with severity labelsA security engineering team wants Claude to classify code findings as CRITICAL, HIGH, MEDIUM, or LOW. Few-shot examples that embed `<thinking>` blocks teach Claude the reasoning chain (e.g., 'hardcoded credential → immediate exposure → CRITICAL') rather than just the label.
  • Schema-constrained JSON extractionA data pipeline ingests free-text product descriptions and must output a fixed JSON schema. Examples demonstrate how Claude should handle missing fields (use null), inconsistent units (normalize to metric), and multi-value attributes (use arrays).

What changed recently

  • 2025Anthropic's official documentation began explicitly recommending embedding `<thinking>` blocks inside few-shot examples to prime adaptive thinking in Claude 3.7 and later models, allowing Claude to generalize the demonstrated reasoning architecture to its own extended thinking blocks.
  • 2025Claude 4.x models (Claude Opus 4, Claude Sonnet 4, Claude Haiku 3.5 and later) were confirmed to process few-shot examples with high fidelity, replicating naming conventions, code style, formatting, and punctuation as demonstrated.
  • 2026-03Claude Code became available to Pro and Max plan subscribers under a unified subscription with shared usage limits, meaning few-shot prompting via CLAUDE.md context files in Claude Code is accessible without a separate API billing account for those users.
  • 2026-03-16Anthropic clarified (support.claude.com) that paid claude.ai subscriptions (Pro, Max, Team, Enterprise) and the Claude API / Console are separate products. A chat subscription does not include API access; API access is billed separately by token usage.
This is the short version

The full chapter has three worked examples, the common pitfalls, and the workflow that makes it pay — plus the other 84 features, kept current.

Get Claude Master — $97
CLAUDEMASTER
An independent publication.
Independent product. Not affiliated with or endorsed by Anthropic. “Claude” is a trademark of Anthropic, used here only to describe the subject of this manual.
© 2026 Claude Master — All rights reserved.