Module 4 · Expert Track15 min read · Prompt Engineering Mastery

Few-Shot and Chain-of-Thought Techniques

Two of the most rigorously studied and consistently effective prompting techniques are few-shot learning — providing examples of input-output pairs to teach the model your specific pattern — and chain-of-thought prompting — instructing the model to reason step by step before reaching a conclusion. Mastering both techniques, and knowing when to apply each, is foundational to expert-level prompt engineering.

Zero-Shot, Few-Shot, and Many-Shot

The "shots" terminology refers to the number of examples included in the prompt. Zero-shot prompting provides no examples — just an instruction and an input. Few-shot provides a small number of input-output examples (typically 2-5) that illustrate the pattern. Many-shot provides a larger set of examples (10, 20, or more) to increase reliability and cover more variation.

Zero-shot works well for tasks that are common and well-represented in the model's training data. Standard summarization, translation, and basic classification all perform adequately zero-shot. When the task is novel, specialized, or requires a specific format the model has not seen frequently, few-shot is dramatically more reliable.

The mechanism is clear: examples communicate requirements that are difficult to specify in abstract language. If you want the model to classify support tickets into five specific categories using a particular naming convention, you can write a paragraph describing the criteria — or you can show three examples. The examples are almost always more reliable because they eliminate the gap between your description and the model's interpretation of it.

Why Examples Work

Examples are the most compact and unambiguous way to communicate a pattern. A single well-chosen example conveys format, style, level of detail, vocabulary, and reasoning approach simultaneously. Three examples can convey variation and boundary cases that would take paragraphs to specify abstractly — and convey them more reliably.

Choosing Good Few-Shot Examples

The quality of your examples matters as much as their quantity. Poor examples teach the wrong pattern or create confounds that mislead the model.

Representative of the Task Distribution
Examples should reflect the range of inputs the model will actually encounter, not just easy or typical cases. If your task includes edge cases or ambiguous inputs, include examples of those. The model generalizes from what you show it.
Internally Consistent
All examples should follow the same pattern, format, and style. Inconsistent examples teach the model that inconsistency is acceptable. If your first example uses markdown headers and your second uses plain text, the model will alternate unpredictably.
Demonstrative of the Hard Cases
If there is a boundary condition where the right answer is non-obvious, include an example of it. "Include this in category A even though it might seem like B because X" teaches the decision rule explicitly. Never rely on the model inferring subtle distinctions from easy examples alone.
Appropriately Detailed
The level of detail in your example outputs sets the expected level for actual outputs. If your examples are brief and direct, the model will produce brief and direct responses. Match the detail level to what you actually need.

Few-Shot Prompt Structure

A standard few-shot prompt has a clear structure: an instruction, followed by labeled examples, followed by the actual input to process.

TASK: Classify customer support tickets as one of: Bug Report, Feature Request, Billing Issue, or General Inquiry. Return only the category label. Input: "The export button on the dashboard stopped working after yesterday's update." Output: Bug Report Input: "Is there any way to get weekly digest emails instead of daily ones?" Output: Feature Request Input: "I was charged twice for my subscription this month." Output: Billing Issue Input: "How do I add a team member to my account?" Output:

The structure cues the model to continue the pattern. Note the final "Output:" with nothing after it — this invites the model to complete the pattern with a classification. The model has three examples establishing the format and three category mappings to generalize from.

Chain-of-Thought Prompting

Chain-of-thought (CoT) prompting is the technique of instructing the model to show its reasoning step by step before producing a final answer. The seminal finding from research is simple and powerful: when models are prompted to think through a problem explicitly, their accuracy on multi-step reasoning tasks improves dramatically compared to prompting for a direct answer.

The most basic version is the phrase "Let's think step by step" appended to a question. This simple addition consistently improves performance on arithmetic, logic, and multi-step reasoning tasks. The reason is intuitive: generating an intermediate reasoning trace forces the model to "commit" to a chain of inferences that is then visible and correctable, rather than jumping directly to a prediction that may be superficially plausible but logically flawed.

Chain-of-Thought Example

Prompt: "A store is selling notebooks for $3.50 each. A customer buys 4 notebooks and pays with a $20 bill. How much change do they receive? Think through this step by step before giving the final answer."

Output: "Step 1: Calculate the total cost. 4 notebooks x $3.50 each = $14.00. Step 2: Calculate the change. $20.00 - $14.00 = $6.00. The customer receives $6.00 in change."

Without the CoT instruction, the model often gives the right answer — but on harder problems, forcing explicit intermediate steps substantially reduces errors and makes reasoning auditable.

Few-Shot Chain-of-Thought

The most powerful version of CoT prompting combines it with few-shot examples: you provide examples that include not just the input and final answer, but the complete reasoning chain in between. This teaches the model both the format of the reasoning trace and the type of reasoning you expect.

Q: Roger has 5 tennis balls. He buys 2 more cans of tennis balls. Each can has 3 balls. How many tennis balls does he have now? A: Roger starts with 5 balls. He buys 2 cans, each with 3 balls, so that's 2 x 3 = 6 additional balls. 5 + 6 = 11. The answer is 11. Q: A juggler has 16 balls. Half of the balls are golf balls. Half of the golf balls are blue. How many blue golf balls are there? A: The juggler has 16 balls total. Half are golf balls: 16 / 2 = 8 golf balls. Half of the golf balls are blue: 8 / 2 = 4. The answer is 4. Q: [YOUR PROBLEM HERE] A:

This few-shot CoT structure reliably produces step-by-step reasoning for new problems. The examples establish the exact format of the reasoning trace you want — the vocabulary, the level of detail, the way intermediate results are stated.

Self-Consistency: Sampling Multiple Reasoning Paths

A powerful extension of chain-of-thought is self-consistency: generating multiple independent reasoning chains for the same problem and then selecting the most common answer. The intuition is that even if any individual chain can go wrong, the correct answer is likely to appear most frequently across multiple independent attempts.

In practice, you implement self-consistency by running the same CoT prompt multiple times (with temperature above 0 to introduce variation), extracting the final answers, and taking the majority vote. Research consistently shows that self-consistency improves accuracy over single-chain CoT, particularly for complex reasoning tasks. For high-stakes applications where reliability matters more than cost, this technique is worth the additional API calls.

When to Use CoT

Chain-of-thought is most valuable for tasks that require multi-step reasoning: mathematical problems, logical deduction, multi-criteria evaluation, planning. It is less valuable for straightforward factual retrieval or simple classification where the answer does not depend on intermediate steps. Forcing CoT on simple tasks adds tokens without improving quality and can sometimes hurt performance by introducing unnecessary complexity.

Zero-Shot CoT: The Magic Phrase

For situations where you cannot provide examples, zero-shot CoT — adding "Let's think step by step" or "Think through this carefully before answering" — still provides meaningful improvement on reasoning tasks. Research has found several effective zero-shot CoT triggers:

  • "Let's think step by step."
  • "Think through this carefully and show your reasoning."
  • "Before answering, work through the problem systematically."
  • "Reason through each part of this problem before giving a final answer."

The exact phrasing matters less than the principle: instructing the model to produce intermediate reasoning steps before committing to a final answer. The instruction to reason explicitly is more important than the specific words used to convey it.

Combining Few-Shot and Role Assignment

Few-shot and role assignment are complementary. Role assignment sets the analytical frame; few-shot examples calibrate the specific output format and style within that frame. A prompt that combines both has a role instruction establishing who the model is, followed by examples showing how that role approaches this specific task type, followed by the actual input. This layering produces the most consistently high-quality outputs for complex, specialized tasks.