Few-Shot Prompting
Teach the AI by example — provide input-output pairs to guide behavior.
Few-Shot Prompting
Few-shot prompting is one of the most powerful techniques in prompt engineering. Instead of describing what you want in abstract terms, you show the AI concrete examples of input-output pairs. The AI then generalizes from these examples to handle new inputs. This technique is especially effective for classification, formatting, and any task where the pattern is easier to show than to explain.
How Few-Shot Works
The basic structure is simple: you provide 2-5 examples of the pattern you want, then give the AI a new input and ask it to continue the pattern. For instance, if you want the AI to classify customer feedback as positive, negative, or neutral, you show it three labeled examples and then give it a new piece of feedback to classify. The AI picks up on the pattern and applies it.
Choosing Good Examples
The quality of your examples matters enormously. Good few-shot examples are representative (they cover the range of cases the AI will encounter), diverse (they are not all the same type), and clear (the correct answer is unambiguous). If all your examples are easy cases, the AI will struggle with edge cases. If your examples are inconsistent, the AI will be confused.
Zero-Shot vs. Few-Shot vs. Many-Shot
Zero-shot means giving no examples — just instructions. This works for simple, well-defined tasks. Few-shot (2-5 examples) works for tasks where the pattern is complex or subtle. Many-shot (10+ examples) can be useful but has diminishing returns and uses up context window. For most tasks, 3-5 well-chosen examples hit the sweet spot.
Time to Practice
In the exercise below, you will write a few-shot prompt for a text classification task. Your goal is to provide clear examples that teach the AI the classification scheme, then set it up to classify new text correctly.