- Blog
- Crafting effective examples
Crafting effective examples
Crafting effective examples
To get the most out of using examples in your prompts, consider the following guidelines on how to provide the most effective examples:
- Relevance: Ensure that your examples closely resemble the types of inputs and outputs you expect Claude to handle. The more similar the examples are to your actual use case, the better Claude will perform.
- Diversity: Include a variety of examples that cover different scenarios, edge cases, and potential challenges. This helps Claude generalize better and handle a wider range of inputs.
- Clarity: Make your examples clear, concise, and easy to understand. Use formatting tags like
<example>
to structure your examples and distinguish them from the rest of the prompt. Give Claude context as to what kind of example it's about to encounter when possible (e.g.,Here are some examples of proper APA citations
orHere are some examples of emails I've written
). - Quantity: While there's no hard rule for the optimal number of examples, aim to provide at least 3-5 examples to start to give Claude a solid foundation. You can always add more targeted examples if Claude's performance isn't meeting your expectations.
To provide examples, simply include them in your prompt, clearly distinguishing them from the actual task. We recommend using <example></example>
tags to wrap your examples, making it easy for Claude to differentiate between the examples and the rest of the prompt.
Here's a prompt that demonstrates the use of examples to guide Claude's response:
plaintext
In this prompt, the example provides Claude with guidance on how to extract the author's name from a given quote, making it easy for Claude to replicate the process on a new input.
Formatting outputs
Examples are particularly effective for tasks that require structured or formatted outputs. Sometimes, instead of providing step-by-step formatting instructions, you can simply include a few examples of the desired output format (although we recommend having both instructions and examples together, as that is likely to be more effective than one without the other).
Suppose you want Claude to extract names and professions from a given text and format them as a list. Here's how you might prompt Claude with examples:
plaintext
By observing these examples, Claude learns to extract the relevant information and format it as a numbered list with names and professions in the desired style.
A word of caution
While examples are incredibly powerful, it's important to be mindful of potential pitfalls. Claude may sometimes pick up on unintended patterns in your examples, leading to overfitting or unexpected behaviors.
For instance, if all your example emails end with "Sincerely," Claude might learn to always sign off that way for emails it generates, even if it's not appropriate for every case. To mitigate this, ensure your examples are diverse and representative of the full range of desired outputs.
Iterating and refining
Crafting the perfect set of examples often involves iteration and refinement. If Claude's performance isn't quite meeting your expectations, consider the following:
- Analyze the output: Look for patterns in Claude's responses that deviate from what you want. This can help you identify areas where your examples might be unclear or misleading, or where more examples might help.
- Add more examples: If Claude struggles with certain types of inputs, provide additional examples that specifically address those scenarios.
- Revise existing examples: Sometimes, even small tweaks to your examples can make a big difference. Experiment with different wordings, formats, or structures to see what works best.
- Get Claude's help: Writing good examples is hard! You can ask Claude to evaluate the diversity or relevance of your examples for a given task, or generate new examples given a set of existing examples to reference.
Remember, prompt engineering is an iterative process. Don't be discouraged if your initial examples don't yield perfect results – with a bit of tweaking and experimentation, you'll be able to unlock Claude's full potential and achieve exceptional results for your applications.
分享
给我一篇关于如何提升语言模型性能的文章
你都有哪些功能?
请帮我写一篇1000字的文章。
深度思考