少样本提示示例2026
只用2-3个例子就能大幅改变LLM输出格式和风格。
Few-Shot Prompting Examples 2026: The Technique That Teaches LLMs Without Training
Few-shot prompting means putting examples of the desired input-output behavior directly in the prompt. It is the cheapest way to control format, tone, and reasoning style - no fine-tuning, no training data, just context.
Why It Works
LLMs are extremely good at pattern matching from context. Two or three well-chosen examples act as a style guide: the model infers the transformation rule and applies it to new inputs. The technique was formalized in the GPT-3 paper (Brown et al., 2020).
Example 1: Format Control
Extract the company, amount, and date from invoices. Invoice: "Acme Corp, $1,240.50, due 2026-08-15" Output: Company: Acme Corp | Amount: $1240.50 | Date: 2026-08-15 Invoice: "Globex LLC, $89.00, due 2026-09-01" Output: Company: Globex LLC | Amount: $89.00 | Date: 2026-09-01 Invoice: "Initech, $4,500, due 2026-08-30" Output:
Example 2: Sentiment with Explanation
Classify review sentiment and explain in one line. "Battery dies in 2 hours" -> Negative: battery life is terrible. "Love the screen brightness" -> Positive: display quality praised. "It works but setup was confusing" -> Mixed: functional, poor onboarding. "Worth every penny" -> Positive: good value for price. "Case scratches after a week" ->:
Example 3: Code Generation Style
Convert English to Python, using type hints. "Add a user with email and name" -> def add_user(email: str, name: str) -> None: ... "Fetch user by id" -> def get_user(user_id: int) -> User | None: ... "Delete all inactive users" ->:
Best Practices
| Rule | Why |
|---|---|
| 2-5 examples | Enough signal, few tokens |
| Diverse examples | Cover edge cases |
| Examples match target domain | Same vocabulary as real input |
| Put examples BEFORE the real query | Models weight later context |
| Keep output format identical | Model copies the pattern |
FAQ
Few-shot vs zero-shot? Zero-shot = no examples; few-shot = 2-5 examples. Few-shot wins on format-sensitive tasks.
Few-shot vs fine-tuning? Fine-tuning changes the model; few-shot changes the prompt. Few-shot is instant and free, fine-tuning is for high-volume production where prompt cost adds up.
How many tokens do examples cost? Roughly 50-200 tokens per example - negligible for most APIs.
