Advanced Prompting: CoT, Few-shot, ReAct
Read a little, play a little. No scary maths, and no rush.
Show, don't just tell
Basic prompts describe the task. Advanced techniques demonstrate the thinking — and models imitate demonstrated reasoning far better than described instructions. Three patterns cover most of what "prompt engineering experts" actually do.
Few-shot: examples as specification
Two or three input→output pairs pin down format, tone, and edge handling better than paragraphs of rules:
Review: "Battery died day one" → Sentiment: negative
Review: "Arrived early, works great" → Sentiment: positive
Review: "It's okay I guess" → Sentiment:
The model continues the pattern. Curate examples covering your tricky cases (sarcasm, mixed feelings) — the examples are the spec.
Chain-of-thought: think out loud
Appending "think step by step, then give the final answer:" dramatically improves math, logic, and multi-hop questions — the model gets scratch space instead of blurting the first plausible token. For critical decisions, add self-consistency: sample 3 reasoning paths and take the majority answer. Costs 3× tokens, buys real reliability.
ReAct: reasoning that touches tools
ReAct alternates Thought → Action → Observation: "I need the order status [thought] → call get_order(12847) [action] → status: shipped [observation] → ..." Each observation grounds the next thought, so errors get caught mid-loop instead of compounding. This loop is the atomic unit of AI agents — see /animations/agent-loop.
Reasoning models change the advice
A newer class of models, often called reasoning models, does its step-by-step thinking internally before writing the answer. With them, adding "think step by step" usually adds little, and long hand-written reasoning instructions can even get in the way. What helps instead is a clear statement of the goal, the constraints, and what a good answer looks like. Check your provider's guidance for the specific model, because the right prompting style genuinely differs between model types.
Keeping the reasoning out of the user's view
Chain-of-thought produces useful working, but users usually want only the conclusion. Ask for both in separate places, for example JSON with a reasoning field followed by an answer field, or a line that begins Final answer:. Your code shows only the answer and can log the reasoning for debugging.
Prompt chaining: one job per call
Instead of one giant prompt that extracts, analyzes, and writes, split the work into a chain: one call extracts the facts, a second analyzes them, a third writes the reply. Each step has a simple prompt, can be tested on its own, and can use a different model, perhaps a cheap one for extraction and a stronger one for the final writing. When something goes wrong, you can see exactly which step failed.
Choosing a technique
- Output in the wrong format or tone: add few-shot examples.
- Wrong answers on multi-step problems: chain-of-thought, then self-consistency if the stakes justify the cost.
- Needs facts it does not have, or actions in the world: tools and a ReAct-style loop.
- Answers vary run to run: lower the temperature before reaching for anything clever.
- The model ignores a rule: move the rule into the system message and state it as a positive target rather than a prohibition.
Remember this
- Few-shot for format, chain-of-thought for reasoning, ReAct when tools are involved.
- Harder tasks deserve more tokens: self-consistency and explicit steps are compute well spent.
Check your understanding
5 questions · first-try answers earn the most XP
My notes
Saved in this browser. Highlight a line above and save it, or write it in your own words.
Nothing saved yet. Your highlights will live here.
References
Finished reading?
Ticking it here also ticks the chapter in the sidebar, the section count and your streak — it is all one number.
Related chapters
Spotted a mistake or want a topic covered? Report an issue