Few-shot
Medium — good to knowAI & ML
ELI5 — The Vibe Check
Showing the AI a few examples of what you want before asking it to do the real thing. Like 'here are 3 examples of good commit messages. Now write one for this diff.' The examples teach the AI your style and expectations without any actual training.
Real Talk
Few-shot prompting provides a small number of input-output examples in the prompt to demonstrate the desired behavior. It leverages in-context learning — the model's ability to learn patterns from examples within the context window without weight updates. Typically 2-5 examples suffice.
Show Me The Code
# Few-shot prompt for commit messages
Examples:
- diff: +login button → msg: "Add login button to homepage"
- diff: -console.log → msg: "Remove debug logging"
- diff: +retry logic → msg: "Add retry with exponential backoff"
Now write a commit message for this diff:
+ dark mode toggle
When You'll Hear This
"Add a few-shot examples to get more consistent output." / "Few-shot prompting fixed my formatting issues."