AlgoMaster Logo

Exercise: Advanced Prompting Techniques

3 min readUpdated June 22, 2026
Listen to this chapter
Unlock Audio

Exercise 1: Few-Shot vs Zero-Shot

Classify text into a custom set of labels two ways: once with a plain instruction (zero-shot) and once with a few labeled examples in the prompt (few-shot). Compare how the examples change the model's output format and accuracy.

Few-shot prompting is the fastest way to steer a model toward a specific output format or a task it does not handle well by default. Showing two or three worked examples often does more than a paragraph of instructions, because the model copies the pattern it sees rather than interpreting a description.

Requirements

  • Define a small set of texts to classify into the labels billing, technical, or account.
  • Build a zero-shot prompt that only describes the task, and classify each text.
  • Build a few-shot prompt that includes two or three labeled examples, and classify each text.
  • Print both sets of predictions side by side.
main.py
Loading...

Expected Output

Both approaches usually get easy cases right, but the few-shot version is more consistent about returning just the label.

Solution

main.py
Loading...

The few-shot version carries its examples as alternating user and assistant turns, which is how you show the model a worked pattern in chat format. Those turns demonstrate both the mapping (this kind of message gets this label) and the exact output shape (a bare label, not a sentence). That demonstration is usually a stronger signal than the instruction alone, which is why few-shot output tends to be more consistent and easier to parse.

Exercise 2: Chain-of-Thought Prompting

Asking a model to show its reasoning before answering often improves accuracy on multi-step problems. Pose a small arithmetic word problem two ways, once demanding only the answer and once asking it to think step by step, and compare the results.

Requirements

  • Ask the question directly, requesting only the final number.
  • Ask again, appending an instruction to reason step by step and then give the answer.
  • Print both responses and compare.
main.py
Loading...

Expected Output

The direct answer is sometimes wrong; the step-by-step version reasons to the correct $50.

Solution

main.py
Loading...

Reasoning takes tokens, and a direct answer gives the model no space to work through the steps, which is where multi-step problems go wrong. Adding "think step by step" lets the model lay out intermediate results before committing, and the explicit "Answer:" line gives you a stable place to parse the final value from. The cost is more output tokens and latency, so you reserve chain-of-thought for tasks where the reasoning actually changes the answer.