skipLink.label

Quest 19 - Chain-of-Thought Prompter

Quest 19: Chain-of-Thought Prompter

medium 25 minutes

🎯 Learning Objectives

  • ✅ Understand chain-of-thought prompting and why step-by-step reasoning improves accuracy
  • ✅ Structure prompts that elicit explicit reasoning from LLMs
  • ✅ Break complex problems into verifiable reasoning steps
  • ✅ Apply CoT patterns to improve performance on math, logic, and multi-step tasks

📖 Concept: Chain-of-Thought Prompting

Chain-of-Thought (CoT) prompting คือ technique ที่สั่งให้ LLM “คิดให้เห็น” แทนที่จะข้ามไปคำตอบโดยตรง ผลลัพธ์คือ accuracy ที่สูงขึ้นมากสำหรับ tasks ที่ต้องใช้ reasoning

แทนที่จะถาม “2 + 2 เท่ากับเท่าไหร่?” ตรง ๆ CoT จะถามว่า “คิดทีละขั้น: 1) 识别 operation, 2) คำนวณ, 3) ตรวจสอบคำตอบ” ทำให้ model ไม่ข้าม step และมี chance แก้ไขตัวเอง

เหมือน martial arts: แทนที่จะจำ technique ทั้งหมดทีเดียว CoT คือการ breakdown เป็นท่าเล็ก ๆ ที่ฝึกทีละ step จนกลายเป็น muscle memory


⚙️ How It Works

The CoT Workflow

1. Receive problem and reasoning steps
↓
2. Format prompt with structured steps
├── Include the problem statement
├── List reasoning steps explicitly
├── Add "Let's think step by step" pattern
└── Separate each step clearly
↓
3. Return formatted prompt
↓
4. LLM processes each step sequentially
↓
5. More accurate final answer

Why CoT Works

ApproachProcessAccuracy
Direct promptProblem → AnswerLow for complex tasks
CoT promptProblem → Step 1 → Step 2 → … → AnswerHigh

CoT forces the model to use its intermediate tokens for computation, not just storage.


💡 Example: Building a CoT Prompt

Step 1: Basic structure

function buildCoTPrompt(problem, steps) {
let prompt = `Problem: ${problem}\n\n`;
prompt += "Let's think step by step:\n\n";
steps.forEach((step, i) => {
prompt += `Step ${i + 1}: ${step}\n`;
});
prompt += "\nNow provide your answer based on the above reasoning.";
return prompt;
}

Step 2: Usage example

const prompt = buildCoTPrompt(
"What is 2+2?",
["Identify the operation (addition)", "Compute 2+2 = 4", "Verify: 4 is reasonable"]
);

Step 3: Verify the output

Terminal window
node test.js
# Test: contains the problem
# Test: contains step-by-step indicator
# Test: contains all steps
# Test: not just the problem passed through

⚠️ Common Mistakes

Mistake 1: Returning the problem as-is

return problem without any structuring → CoT requires explicit step structure. Pass-through defeats the purpose.

Mistake 2: Not including a reasoning indicator

Missing “Let’s think step by step” or similar phrase → This phrase triggers the model’s reasoning mode. Without it, CoT is less effective.

Mistake 3: Steps that are too vague

“Think about it” instead of specific reasoning steps → Each step should be a concrete, verifiable action.

Mistake 4: Not handling empty steps

Crashing when no steps are provided → Always handle the edge case gracefully — return at least the problem with the CoT trigger phrase.


📝 Knowledge Check

📝 Knowledge Check

Q1:What is chain-of-thought (CoT) prompting?

Q2:Why does CoT prompting improve accuracy on math problems?

Q3:What should a CoT prompt include even when no steps are provided?


🏋️ Quest: Chain-of-Thought Prompter

Now it’s time to build structured reasoning prompts!

  1. Download ไฟล์เริ่มต้นของ quest:

    Terminal window
    npx bluebeltdojo download quest-19-chain-of-thought
    cd quest-19-chain-of-thought
  2. เปิด problem.js ใน editor ของคุณพร้อมความช่วยเหลือของ AI

  3. Implement buildCoTPrompt(problem, steps) — สร้าง structured reasoning prompt

  4. ทดสอบ edge cases: empty steps, single step, multiple steps

  5. ตรวจสอบ solution ของคุณ:

    Terminal window
    node test.js
  6. When all tests pass, submit your solution:

    Terminal window
    npx bluebeltdojo submit

💡 Tip: CoT prompting คือ one of the simplest but most powerful techniques — ลองกับ math problems แล้วจะเห็นผลทันที


คำใบ้

  • อ่าน instructions ใน problem.js อย่างละเอียด
  • ตรวจสอบ: prompt ต้องมี “step by step” indicator และ step ทั้งหมด
  • ถ้าติดขัด ลองอ่าน “Common Mistakes” อีกครั้ง — อย่าดู solution โดยตรง