Anybody Can AI

Quick Stats

Completed

0

Time Spent

0m

Streak

0

User

User

Prompt Engineering Mastery

Core Techniques/Chain-of-Thought & Structured Output

Chain-of-Thought & Structured Output

Reasoning and clean formats.

Let the model think

For anything with multiple steps — math, logic, planning, careful analysis — the single most effective trick is to ask the model to reason step by step before giving the answer. Working through the intermediate steps dramatically improves accuracy, because each step becomes context the model can build on instead of trying to leap to the answer in one jump.

A simple version: add "Let's work through this step by step" or "Show your reasoning, then give the final answer." On hard problems the gain in reliability is large.

Why it works

The model generates one token at a time, each conditioned on what came before. When it writes out the reasoning, those intermediate tokens become a scaffold the final answer rests on. Skip the scaffold and it has to compress all the thinking into a single guess — exactly where mistakes creep in.

Get machine-readable output

When another program — not a human — will read the result, ask for a strict, parseable format:

Return ONLY valid JSON: {"summary": string, "tags": string[]}

Be explicit: name the fields, give the types, and say "only" so it doesn't wrap the JSON in chatty preamble. For classification, spell out the exact allowed values.

Combining the two

Reasoning and clean output can fight each other — step-by-step thinking is the opposite of "only JSON." The fix is to separate them: let the model reason first in plain text, then put the final result in a clearly delimited block you can extract and parse.

Two levers, two jobs: chain-of-thought buys you accuracy, structured output buys you reliability. Reach for the first when the problem is hard, the second when a machine reads the answer.

Try this: Give the model a word problem twice — once asking only for the final number, once asking it to reason step by step first. Compare. The step-by-step version is usually right, and you'll see exactly where the one-shot answer went wrong.