Prompt Engineering: Few-Shot Examples and Reasoning
Edited by Dev Kilaru, Senior Data Analyst. How we make our content
Introduction
Two of the most effective techniques in prompting are showing examples of what you want, and giving the model room to reason before it answers. This lesson covers both: how to write good few-shot examples, and how reasoning works with modern models.
Prerequisites
- The structured prompts lesson
Step-by-Step Guide
Step 1: Use examples to pin down format and judgment
When instructions alone leave room for interpretation, show the model a few input and output pairs. This is called few-shot prompting. Examples are especially good at fixing output format, tone, and borderline decisions.
Classify the sentiment of each review as positive, negative, or mixed.
<example>
Review: Fast shipping and the book is beautiful.
Sentiment: positive
</example>
<example>
Review: Arrived late and the cover was torn.
Sentiment: negative
</example>
<example>
Review: Great story, but the print quality is poor.
Sentiment: mixed
</example>
Review: I love the plot but the ending disappointed me.
Sentiment:Step 2: Write examples that generalize
Use varied examples that cover the range of cases, including tricky ones, and keep their format identical. If all your examples look alike, the model may copy surface patterns. Label them clearly as examples so they are not mistaken for the real input.
Step 3: Let the model reason on hard problems
Multi-step problems such as math, planning, and debugging improve when the model reasons before answering. You can ask for a short step-by-step explanation before the final answer, which also lets you check the logic.
Solve the problem. First write your reasoning step by step,
then give the final answer on a line starting with "Answer:".Step 4: Use built-in reasoning controls where available
Many current models reason internally before replying, and some let you control how much effort to spend. Higher effort helps on difficult tasks and costs more time and tokens, while low effort suits simple lookups and classification. Test the setting on your own examples instead of assuming more is always better.
response = client.messages.create(
model="claude-opus-5-5",
max_tokens=16000,
output_config={"effort": "high"}, # low | medium | high | xhigh | max
messages=[{"role": "user", "content": "Plan a 3-step migration from MySQL to Postgres."}],
)Step 5: Break big tasks into smaller steps
If one prompt is trying to do too much, split it: extract the facts first, then analyze, then write. Each step is easier to test and debug, and you can feed one step's output into the next.
FAQs
- How many examples should I include?
- Often three to five varied examples are enough. Add more only if the model still misjudges certain cases, and add examples that target exactly those failures.
- Is 'think step by step' still necessary?
- For models that already reason internally it is often unnecessary and the effort setting does more. It can still help with models that do not, or when you want the reasoning visible in the answer. Measure on your own tasks.
Summary
Show examples to lock in format and judgment, give the model room to reason on hard problems, use effort controls when available, and split complex work into steps you can test.
Comments
Log in or create a free account to join the discussion.