Advanced Prompt Engineering
Advanced Prompt Engineering Strategies

Chain-of-Thought
& Few-Shot Prompting

Two foundational techniques that transform how large language models reason, generalise, and produce reliable, structured responses.

Strategy Guide Vol. II LLM Engineering Series
02

Prompts are not just instructions — they are cognitive scaffolds that shape how a model thinks, step by step, example by example.

Few-Shot Prompting

Few-shot prompting teaches a model by demonstration rather than description. Instead of explaining the task in abstract terms, you provide a small number of fully-worked input–output examples directly in the prompt. The model infers the pattern and applies it to new inputs.

This is powerful because LLMs are trained to complete sequences. By prepending examples, you effectively condition the model’s generation process on a concrete behavioural template.

Few-Shot Prompt — Sentiment Classification
# System context (optional)
System: Classify the sentiment of each review as Positive, Negative, or Neutral.

# Example 1
Input:  "The delivery was fast and the packaging was pristine."
 Output: Positive

# Example 2
Input:  "It works, I suppose. Nothing special."
 Output: Neutral

# Example 3
Input:  "Broke after two days. Complete waste of money."
 Output: Negative

# New query — model completes the pattern
Input:  "Exceeded every expectation. Already ordered a second one."
 Output: ← model generates this
Key Principle

Quality Over Quantity

Research shows diminishing returns beyond 8–16 examples for most tasks. Three to five well-chosen, diverse, and correctly-formatted exemplars almost always outperform ten mediocre ones. Prioritise coverage of edge cases over raw volume.

When to use Few-Shot
Task format is rigid or non-obvious
Output schema must be consistent (JSON, tables)
Domain vocabulary or tone matters
Zero-shot results are inconsistent
Classification with custom label sets
Limitations to watch
Consumes significant context window tokens
Example bias can distort edge-case responses
Poor examples actively harm performance
Order of examples affects output quality
Not a substitute for fine-tuning at scale
§

Chain-of-Thought Prompting

Chain-of-Thought (CoT) prompting elicits step-by-step reasoning from a model before it commits to a final answer. Rather than jumping to a conclusion, the model is guided — either by examples or by a simple instruction — to externalise its intermediate reasoning process.

This dramatically improves performance on tasks requiring multi-step arithmetic, logical inference, commonsense reasoning, and symbolic manipulation, because errors in intermediate steps become visible and correctable.

Chain-of-Thought Prompt — Logic Problem
User: A store sells apples for $0.50 each and oranges for $0.75 each.
      Maria buys 6 apples and 4 oranges. She pays with a $10 bill.
      How much change does she receive?

      Think through this step by step before giving your answer.

Model:
Step 1 — Cost of apples:   6 × $0.50 = $3.00
Step 2 — Cost of oranges:  4 × $0.75 = $3.00
Step 3 — Total cost:       $3.00 + $3.00 = $6.00
Step 4 — Change:           $10.00 − $6.00 = $4.00

Answer: Maria receives $4.00 in change.
1

Zero-Shot CoT — The Magic Phrase

Simply appending “Think step by step” or “Let’s reason through this carefully” to a prompt reliably triggers chain-of-thought behaviour in capable models, with no examples required. Discovered by Kojima et al., 2022.

2

Few-Shot CoT — Reasoning by Example

Combine both techniques: provide 2–4 examples where each example includes the full reasoning trace alongside the correct answer. The model learns both what to conclude and how to get there.

3

Self-Consistency — Sample & Vote

Generate multiple independent CoT chains for the same question, then select the most frequently occurring final answer. This ensemble approach significantly reduces variance on complex reasoning benchmarks.

4

Tree-of-Thought (ToT) — Branching Reasoning

An extension where the model explores multiple reasoning branches simultaneously, evaluates each branch’s promise, and backtracks when a path fails. Particularly effective for planning, search, and puzzle-solving tasks.

Advanced Pattern

Few-Shot + CoT Combined

The most robust approach for complex tasks: provide 3–5 examples that each demonstrate explicit step-by-step reasoning, followed by the new query with an instruction to reason before answering. This leverages the complementary strengths of both techniques simultaneously.

§

Choosing the Right Strategy

The two techniques are complementary, not competing. Your choice depends on the nature of the task, token budget, and whether you need the model to produce structured output or demonstrate auditable reasoning.

Decision Matrix
Task type             → Recommended strategy
──────────────────────────────────────────────────────────
Format/schema outputFew-Shot (show exact structure)
Multi-step arithmeticCoT (externalise calculation)
ClassificationFew-Shot (define label vocabulary)
Logical inferenceCoT or Few-Shot CoT
Complex reasoningFew-Shot CoT + Self-Consistency
Creative generationFew-Shot (style anchoring)
Planning / puzzlesTree-of-Thought
Simple Q&A            → Zero-Shot (CoT optional)

Best Practice: Always test zero-shot first as your baseline. Add few-shot examples when consistency or format compliance is low. Layer in chain-of-thought reasoning when accuracy on multi-step tasks remains insufficient. Reserve self-consistency sampling for high-stakes outputs where correctness matters more than latency.

LLM Engineering Series · Vol. II

Chain-of-Thought · Few-Shot
Advanced Strategies Reference

Leave a Reply

Your email address will not be published. Required fields are marked *