Few-Shot Prompting, Chain of Thought and Step-by-Step Reasoning: Teaching the Model by Example

LLM Development 50 min min read Updated: Nov 21, 2026 Beginner
Few-Shot Prompting, Chain of Thought and Step-by-Step Reasoning: Teaching the Model by Example
Beginner Topic 2 of 3

Zero-Shot, One-Shot and Few-Shot

TypeMeaning
Zero-shotOnly instructions, no examples
One-shotInstructions plus one example
Few-shotInstructions plus a few examples

Showing examples teaches the model the format and style you want without any training. This is called in-context learning.

A Few-Shot Prompt

python examples = [ ("The delivery was late and the box was damaged.", "negative"), ("Great quality, arrived early!", "positive"), ("It works, nothing special.", "neutral"), ] def few_shot(text): lines = ["Classify the sentiment as positive, negative or neutral.", ""] for t, label in examples: lines.append(f"Review: {t}\nSentiment: {label}\n") lines.append(f"Review: {text}\nSentiment:") return "\n".join(lines) print(few_shot("I love it but shipping took too long."))
Result

Classify the sentiment as positive, negative or neutral. | | Review: The delivery was late and the box was damaged. | Sentiment: negative | | Review: Great quality, arrived early! | Sentiment: positive | | Review: It works, nothing special. | Sentiment: neutral | | Review: I love it but shipping took too long. | Sentiment:

Choose examples well Use clear, varied examples that match real inputs. Include tricky ones. Keep the order and format identical.

Chain of Thought

For problems with several steps, ask the model to work step by step before it answers. Written steps often improve accuracy on math, logic and planning.

text Question: A shop sells pens at 12 each. A customer buys 7 pens and pays with 100. How much change? Think step by step, then give the final answer on a line starting with 'Answer:'.

You can check that kind of answer yourself:

python price, qty, paid = 12, 7, 100 total = price * qty print("total =", total, " change =", paid - total)
Result

total = 84 change = 16

Newer reasoning models Some models do their own step by step thinking internally. For them, simple, direct instructions often work best. Read your provider's guidance and test.

Self-Check Prompts

  • Ask the model to verify its answer against the source text
  • Ask for evidence: the sentence from the document that supports each claim
  • Ask it to say unknown when unsure
Steps can still be wrong A neat explanation is not proof. For math and data, use code or tools to check.

Practice

  1. Add a fourth example to the few-shot demo
  2. Write a chain of thought prompt for a distance and speed problem
  3. Compare answers with and without examples

Conclusion

Examples teach format, step by step prompts help reasoning, and checks catch errors.

Quick Summary: Few-shot; in-context learning; chain of thought; self-check.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators