Bible Network Crypto DeFi Onchain RWA AI Agent Stablecoin Chain SAFU CryptoTax DeFAI AGI Claude Me Claude Skill Claude Design Claude Cowork
Independent Media
Not affiliated with any project
Exploring the Frontier of AI Intelligence
claude-me.com
LATEST
MCP for Developers: Build Your First MCP Server from Scratch  ·  MCP for Non-Developers: Connect Claude to Your Everyday Tools Without Writing a Single Line of Code  ·  Claude Projects Deep Review: Three Months of Real Use — My Honest Assessment  ·  Claude vs ChatGPT 2026: An Honest Comparison — Not Who's Better, But Which One Is Right for You  ·  The Right Way to Debug With Claude: Not Pasting Errors and Waiting, But Systematic Problem-Finding Together  ·  Using Claude to Write Weekly Reports: From Messy Notes to a Report Your Manager Will Actually Read
Glossary · Prompt Techniques

Few-Shot Prompting

Prompt Techniques 新手

30-Second Version · For the impatient
Providing 2–5 input-output examples in the prompt, letting Claude infer the format and style you want from the examples, then apply the same pattern to new inputs. The core implementation of "examples beat explanations."
Full Explanation +
01 · What is this?
Few-Shot Prompting is a technique that provides 2–5 "input → output" paired examples directly in the prompt, letting Claude automatically infer the format, classification criteria, tone, or processing logic you want from those examples, then apply the same rules to your new input. The "Few-Shot" name corresponds to machine learning terminology: Zero-Shot means asking without any examples; One-Shot means providing one example; Few-Shot means providing a small number of examples (typically 2–5); Many-Shot means providing many examples. In practical use, "Few-Shot Prompting" commonly refers to the general practice of providing examples. The core problem it solves: some output formats you want are difficult to describe in words, but immediately clear from a single example. Rather than spending three paragraphs describing the format you want, just provide two examples — Claude's ability to infer rules from examples is often more precise than anything you could describe verbally.
02 · Why does it exist?
Few-Shot Prompting works because Claude learned the ability to "infer patterns from examples" during training. This capability is called "In-Context Learning" — without updating model parameters, simply providing a few examples in the context lets Claude automatically identify patterns and apply them. Why is this ability so strong? Because Claude's training data contained vast amounts of text about pattern recognition tasks — humans explaining rules frequently use phrases like "for example," "such as," "like this" to illustrate with examples, and Claude learned to extract rules from those illustrations. More technically: each example (input-output pair) becomes part of the context window. When generating new output, Claude uses these examples as reference, converging toward "the token generation that best fits the pattern established by these examples." The clearer and more consistent the examples, the more precisely Claude can converge.
03 · How does it affect your decisions?
Few-Shot Prompting's impact on you is mainly about being able to calibrate Claude's output to the format you want. Often, dissatisfaction with Claude's output isn't because its knowledge is insufficient — it's because Claude doesn't know what format, style, or level of detail you want. In batch processing scenarios, this technique's value is high: if you need Claude to process a hundred customer reviews, data records, or article summaries, you can't give individual instructions for each. Few-Shot Prompting lets you "define the rules" with 3–4 examples, then Claude maintains consistent formatting across all subsequent inputs. For developers: when building AI applications, Few-Shot Prompting is one of the most reliable methods for achieving "controllable output format" — more precise than describing format requirements in natural language, far cheaper than fine-tuning. If you need Claude to output fixed-format JSON, the best approach is typically to provide several correct JSON examples rather than only describing the JSON structure in text.
04 · What should you do?
**Immediately usable Few-Shot formats:** Basic format (classification task): ``` Classify the following reviews. Review: "The product quality is terrible" → Category: Negative | Sentiment: Angry Review: "Beautiful packaging, perfect for gifting" → Category: Positive | Sentiment: Satisfied Review: "It's okay, nothing special" → Category: Neutral | Sentiment: Indifferent Now classify: "Shipping was super fast, arrived in one day!" ``` Format conversion task: ``` Rewrite informal descriptions into formal product specification language. Informal: "The battery lasts a really long time" Formal: "Battery life: up to [X] hours of continuous use per charge" Informal: "The screen is big and sharp" Formal: "Display: [X]-inch [X]x[X] resolution, [X] nits brightness" Informal: "This app is slow to open" Formal: ``` **Few-Shot quality rules:** - Examples must be completely consistent in format (don't use commas in one and semicolons in another) - Examples should cover different cases (don't use all the same type of positive example) - 3 examples is typically better than 2; 5 is better than 3; beyond 8, diminishing returns usually set in - Your new input format must exactly match the input format in the examples
Real-World Example +
Lisa manages customer service analytics for an e-commerce platform. Every week she needs to classify hundreds of customer reviews into four categories — "product issue," "logistics issue," "service issue," "positive feedback" — and tag each with sentiment (positive/negative/neutral) and priority (high/medium/low). **Previous approach**: she described the classification criteria in detail each time, but Claude's classifications frequently diverged from her expectations, requiring extensive correction. **After switching to Few-Shot Prompting**: ``` Please classify the following customer reviews using a fixed output format. Review: "Product description looks nothing like what arrived, requesting refund" → Category: Product Issue | Sentiment: Negative | Priority: High Review: "Waited three weeks, customer service won't respond" → Category: Logistics Issue | Sentiment: Negative | Priority: High Review: "Beautiful packaging, friend loved it, will order again" → Category: Positive Feedback | Sentiment: Positive | Priority: Low Review: "Customer service was great and solved my problem, but the product itself is mediocre" → Category: Product Issue | Sentiment: Neutral | Priority: Medium Now classify the following reviews: [paste this week's review list] ``` Result: Claude's output format is completely consistent; classification accuracy improved from ~70% to 90%+; Lisa's weekly correction time dropped from 2 hours to 20 minutes. The fourth example was key — a "mixed case" that taught Claude the rule for reviews involving both service and product issues.
Diagram
Few-Shot Prompting — Structure and How It WorksEXAMPLES SECTION (your prompt)Example 1Input: "The product arrived damaged and I'm very frustrated."Output: Sentiment: Negative | Category: Damage | Priority: HighExample 2Input: "Delivery was fast, very happy with my purchase!"Output: Sentiment: Positive | Category: Delivery | Priority: LowExample 3Input: "Where is my order? It's been 2 weeks."Output: Sentiment: Negative | Category: Shipping | Priority: HighNew Input (to classify):"The color doesn't match what was shown on the website."Claudeinfersthe ruleInferred Rules• Format: 3 fixed fields• Sentiment: Pos/Neg/Neutral• Category: topic of complaint• Priority: High if frustrated or urgent, Low if satisfied• Pipe " | " as separator• No extra explanationOutput for new input:Sentiment: Negative |Category: Product | Priority: MidClaude Me · claude-me.com
Feel free to share. Please credit the source.
Common Misconceptions +
✕ Misconception 1
× Misconception 1: More examples is always better — the more the merrier. Examples exhibit diminishing returns. 2–5 examples typically teach Claude the rules you want; beyond 8–10, each additional example produces negligible quality improvement while token costs keep increasing. More importantly, example quality matters more than quantity: 3 high-quality examples covering different cases far outperforms 10 repetitive examples of similar situations.
✕ Misconception 2
× Misconception 2: Few-Shot Prompting can replace all types of explicit instructions. Few-Shot excels at teaching "format" and "classification criteria" — tasks with clear, consistent patterns. For tasks requiring complex reasoning, ethical judgment, or extensive contextual consideration, a few examples alone may be insufficient — these tasks typically need Few-Shot combined with explicit text explanations. Additionally, if your examples themselves are low quality (inconsistent, with fuzzy boundary cases), the rules Claude learns will be inaccurate.
The Missing Link +
Direct Impact
Few-Shot Prompting is one of the highest-value-per-cost prompting techniques — but its applicable boundaries need to be clear. **Advantages**: extremely effective at solving "format consistency" problems; more precise than describing format requirements in natural language; low barrier to use — anyone can apply it immediately; particularly valuable for batch tasks — define rules once, apply repeatedly. **Limitations**: preparing high-quality examples takes time — you need to first be clear about what good output looks like before you can give good examples; limited effectiveness for tasks without strong regularity (tasks requiring subjective judgment or strong context dependence); if the task type has many variants beyond the examples, Claude may not know how to handle unseen edge cases; token costs increase with example count — large-scale batch applications need to consider costs. **Best combinations**: Few-Shot + Role Prompting (set the role first, then give examples); Few-Shot + CoT (examples show reasoning steps, not just input-output pairs).
Ask a Question
Please enter at least 10 characters