Lesson 13.1 · 1 of 6 · 4 min read · Reviewed 24 Nov 2026
Asking for reasoning before the answer
By the end, you can
- Ask for reasoning before an answer.
- Explain why order matters: reasoning first, answer second.
For tasks with several steps, such as applying a policy, doing arithmetic or comparing options, giving the model room to work it through improves accuracy. That’s chain of thoughtChain of thought: Asking or allowing the model to reason step by step before giving its final answer. (CoT).
Order matters
The model writes one tokenToken: The unit a model reads and writes: a word, part of a word, a space or a symbol, mapped to an integer id. at a time, and each token can use everything before it. Reasoning written before the answer can shape the answer. Reasoning written after the answer can only defend a choice already made.
Three levels
- Basic: “Think step by step before answering.”
- Guided: “First list the policy rules that apply. Then check the order against each rule. Then decide.”
- Structured: ask for reasoning in
<thinking>tags and the answer in<answer>tags (13.2).
Guided steps usually beat a bare “think step by step”, because you’ve told the model how to think about this task.
Extended thinking
Models with extended thinkingExtended thinking: A mode in which the model reasons step by step in thinking blocks before giving its final answer. (13.6) reason in a separate thinking block before answering. For those, you often don’t need to ask for CoT in the prompt. Give a clear task and let the effort setting do the work.
Key points
- Asking the model to think step by step before answering improves multi-step reasoning.
- The reasoning must come before the answer; reasoning written after a decision just justifies it.
- Guided steps ('first list the rules, then check each one') work better than a bare 'think step by step'.
Build a guided reasoning prompt
Turn a list of policy rules into a prompt that makes the model check each rule before it decides.
You will have: A prompt builder function plus a checker that rejects replies where the verdict comes before the reasoning.
Steps
- Read the three refund rules and the sample order in the starter.
- Complete build_prompt so it lists every rule, asks for a check of each one in <thinking>, and puts the verdict last in <answer>.
- Complete reasoning_first so it returns True only when every rule is mentioned before the <answer> tag.
- Run it on the two sample replies and confirm only the reason-first reply passes.
Done when
- The printed prompt names all three rules and ends with the instruction to answer in <answer> tags.
- reasoning_first returns True for the reason-first reply and False for the decide-first reply.
- The script prints 'reason-first reply: PASS' and 'decide-first reply: FAIL'.
Open in the Playground No API key needed.
Starter code (Python)
RULES = [
"R1: the item was delivered no more than 30 days ago",
"R2: the item is unused",
"R3: the item is not on the final-sale list",
]
ORDER = "Order 1042: walking boots, delivered 12 days ago, unused, not final sale."
def build_prompt(rules, order):
# TODO: list every rule, ask the model to check the order against each rule
# inside <thinking> tags, then give the verdict (REFUND or NO REFUND) in <answer> tags.
return "Decide if this order can be refunded: " + order
def reasoning_first(reply, rules):
# TODO: return True only if each rule id (R1, R2, R3) appears before "<answer>".
return True
REPLIES = {
"reason-first reply": "<thinking>R1: 12 days, ok. R2: unused, ok. R3: not final sale, ok.</thinking><answer>REFUND</answer>",
"decide-first reply": "<answer>REFUND</answer><thinking>R1 ok, R2 ok, R3 ok.</thinking>",
}
print(build_prompt(RULES, ORDER))
for name, reply in REPLIES.items():
print(name + ":", "PASS" if reasoning_first(reply, RULES) else "FAIL")
Show a solution
RULES = [
"R1: the item was delivered no more than 30 days ago",
"R2: the item is unused",
"R3: the item is not on the final-sale list",
]
ORDER = "Order 1042: walking boots, delivered 12 days ago, unused, not final sale."
def build_prompt(rules, order):
lines = ["You decide refund requests using the rules below.", "", "<rules>"]
lines += rules
lines += ["</rules>", "", "<order>", order, "</order>", "",
"First, inside <thinking> tags, check the order against each rule in turn and say whether it is met.",
"Then, inside <answer> tags, give the verdict: REFUND or NO REFUND."]
return "\n".join(lines)
def reasoning_first(reply, rules):
cut = reply.find("<answer>")
if cut == -1:
return False
before = reply[:cut]
ids = [r.split(":")[0] for r in rules]
return all(i in before for i in ids)
REPLIES = {
"reason-first reply": "<thinking>R1: 12 days, ok. R2: unused, ok. R3: not final sale, ok.</thinking><answer>REFUND</answer>",
"decide-first reply": "<answer>REFUND</answer><thinking>R1 ok, R2 ok, R3 ok.</thinking>",
}
print(build_prompt(RULES, ORDER))
for name, reply in REPLIES.items():
print(name + ":", "PASS" if reasoning_first(reply, RULES) else "FAIL")