🎓 A1Learner
🔍
0 of 50 lessons completed

Prompt Engineering: Chain-of-Thought

Chain-of-thought prompting asks the model to show its working step by step before giving the answer. The steps make the reasoning visible and easier to check.

The refund, worked step by step

Each step checks one fact before the total is given.

A customer wants to return the Willow Linen Cushion. It costs 29 dollars. It is unused. It was bought 10 days ago. The ShopStack return policy allows returns within 30 days for unused items, with a full refund to the original payment method. Think step by step and then give the refund amount.

The same refund without the steps

Without steps the model jumps straight to the answer.

A customer wants to return the Willow Linen Cushion. It costs 29 dollars. It is unused. It was bought 10 days ago. The ShopStack return policy allows returns within 30 days for unused items, with a full refund to the original payment method. Give the refund amount.

A second calculation with steps

The steps work the same way on a different order.

A customer wants to return the Aurora Ceramic Mug and the Trailhead Canvas Tote. The mug costs 18 dollars. The tote costs 26 dollars. Both are unused and within 30 days. The ShopStack return policy allows returns within 30 days for unused items, with a full refund to the original payment method. Think step by step and then give the total refund amount.

Example

A customer wants to return the Hearthstone Desk Lamp. It costs 42 dollars. It is unused. It was bought 5 days ago. The ShopStack return policy allows returns within 30 days for unused items, with a full refund to the original payment method. Think step by step and then give the refund amount.

Key points

  • Chain-of-thought prompting adds one line to the prompt. The line asks the model to think step by step.
  • The model writes each step of the working before it writes the answer.
  • Visible working makes a wrong step easy to spot.
  • A refund calculation is a good chain-of-thought task. The price, the policy and the total each get a step.
  • The final answer follows from the steps, not from a guess.

This example runs a chain-of-thought prompt against the local model and shows the reply it gave. The steps check the price, the condition and the window before the answer.

Note

Chain-of-thought prompting helps when the answer needs working. A simple lookup needs no steps.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Rust Playground

Exercise

What does chain-of-thought prompting add to a prompt?