promptdojo_

Few-shot and reasoning — examples that work, and the CoT trap on reasoning models — step 8 of 9

Write build_prompt(task, examples, query, model) that:

  • Always opens with the task line + a blank line.
  • If examples is non-empty, appends each as "Input: <input>\nOutput: <output>\n\n".
  • Appends the query as "Input: <query>\nOutput:".
  • If model is NOT in REASONING_MODELS, prepends a CoT line ("Think step by step.\n\n") BEFORE the examples — but ONLY if the task involves reasoning (we'll signal this with task.startswith("Solve")). If the task is classification (the Classify prefix in our test), skip CoT regardless of model.
  • Returns the prompt string.

Two cases run for you. Expected output:

--- classify on haiku (no CoT, has examples) ---
Classify sentiment.

Input: great
Output: positive

Input: bad
Output: negative

Input: okay
Output:
---
--- math on o3 (no CoT — reasoning model handles it) ---
Solve: what is 17 * 23?

Input: 17 * 23
Output:

full-screen editor opens — close anytime to keep reading.