Use examples (multishot prompting) to guide Claude's behavior - Anthropic (original) (raw)
Examples are your secret weapon shortcut for getting Claude to generate exactly what you need. By providing a few well-crafted examples in your prompt, you can dramatically improve the accuracy, consistency, and quality of Claude’s outputs. This technique, known as few-shot or multishot prompting, is particularly effective for tasks that require structured outputs or adherence to specific formats.
- Accuracy: Examples reduce misinterpretation of instructions.
- Consistency: Examples enforce uniform structure and style.
- Performance: Well-chosen examples boost Claude’s ability to handle complex tasks.
Crafting effective examples
For maximum effectiveness, make sure that your examples are:
- Relevant: Your examples mirror your actual use case.
- Diverse: Your examples cover edge cases and potential challenges, and vary enough that Claude doesn’t inadvertently pick up on unintended patterns.
- Clear: Your examples are wrapped in
<example>
tags (if multiple, nested within<examples>
tags) for structure.