Lesson 13.5 · 5 of 6 · 6 min read · Reviewed 24 Nov 2026
Self-consistency and tree of thoughts
By the end, you can
- Use self-consistency to make a reasoning answer more reliable.
- Explain how tree of thoughts searches over partial solutions, and when it is worth the cost.
Chain of thoughtChain of thought: Asking or allowing the model to reason step by step before giving its final answer. (13.1) gives the model one path to the answer. If that path takes a wrong turn early, the answer is wrong. Two techniques spend extra calls to make that less likely: self-consistency and tree of thoughts.
Self-consistency: many paths, one vote
The idea is simple. Ask the same question several times with sampling turned on (a temperatureTemperature: A sampling setting that controls randomness: lower values make output more predictable, higher values more varied. above 0), so each run reasons a little differently. Pull out each run’s final answer and take the majority.
Worked example. A support tool must work out the refund for a part-used annual plan. You run five samples:
| Sample | Final answer |
|---|---|
| 1 | 42 credits |
| 2 | 42 credits |
| 3 | 38 credits |
| 4 | 42 credits |
| 5 | 50 credits |
Three of five agree on 42, so you return 42. The two outliers each took a different wrong turn, and wrong turns rarely land on the same wrong answer.
Why it works: if each path is right with probability above one half, and the paths are roughly independent, the majority is right more often than any single path. With paths right 70% of the time, a five-way vote is right about 84% of the time (illustrative, assuming independence).
The agreement rate is also a free confidence signal. Five out of five is safer than three out of five, and a split vote can go to a person.
Tree of thoughts: search, not just voting
Self-consistency runs whole paths and compares the ends. Tree of thoughts works on partial paths:
- At each step, generate a few candidate next steps (the “thoughts”).
- Score each partial path, with the model as judge or with code.
- Keep the most promising branches and drop the rest.
- Repeat until a branch reaches a full solution.
That is a search (breadth-first or depth-first) where the model both proposes and evaluates. It suits puzzles and planning problems where early choices constrain later ones and a dead end can be spotted before the end, such as scheduling with hard constraints.
Comparing the two
| Self-consistency | Tree of thoughts | |
|---|---|---|
| Unit | Whole reasoning paths | Partial steps |
| Combine by | Majority vote on the final answer | Scoring and pruning branches |
| Calls | N (often 3 to 10) | Many: branches times depth, plus scoring |
| Needs | Answers you can compare exactly | A way to judge partial progress |
| Good for | Maths, labels, short factual answers | Planning, puzzles, constraint problems |
When to use it
- The answer is checkable and comparable: a number, a category, a yes or no. VotingParallelization: A workflow pattern that runs several LLM calls at once, either on separate subtasks or as multiple votes on one task. on free-form essays does not work, because no two match.
- A single path is usually right but not reliably. If one path is right only 30% of the time, a vote can make things worse.
- The stakes justify the cost. Five samples cost about five times as much as one.
Common mistakes
- SamplingSampling: Choosing the next token from the model’s probability distribution, rather than always taking the most likely one. at temperature 0. Every path is the same, so the vote adds nothing.
- Voting on the reasoning text instead of a normalised final answer. Strip units and formatting before you count.
- Skipping the evalEval: A repeatable test that measures how well an AI system performs on a set of cases with defined success criteria.. Run your test set with one sample and with five. Keep the extra cost only where the score clearly rises (13.4).
- Reaching for tree of thoughts first. Try guided chain of thought, then a reasoning model (13.6), then self-consistency. Full tree search is the heaviest option.
Key points
- Self-consistency samples several independent reasoning paths and takes the majority final answer.
- It only helps when each path is right more often than wrong and the answers can be compared, such as a number or a label.
- Tree of thoughts branches at each step, scores the partial paths and keeps the best, like a search.
- Both multiply calls and tokens, so use them where an eval shows a real gain on hard, checkable tasks.
Build a self-consistency voter
Implement a majority vote over sampled reasoning paths and see when it beats a single path.
You will have: A vote function with an agreement bar, and a printed comparison of single-path and voted accuracy on 300 simulated questions.
Steps
- Read sample_path: a simulated reasoning path that is right 70% of the time and otherwise returns one of several wrong answers (seeded, so results repeat).
- Complete normalise so '42 credits', ' 42' and '42.0' all count as the same answer.
- Complete vote so it returns the most common answer and its share of the samples.
- Route any question whose winning share is below 0.6 to review, then compare accuracy.
Done when
- Voted accuracy on accepted questions is higher than single-path accuracy.
- The script prints 'single path accuracy', 'vote accuracy (accepted)' and how many were routed to review.
- Re-running gives the same numbers, because the random generator is seeded with 7.
Open in the Playground No API key needed.
Starter code (Python)
import random
from collections import Counter
rng = random.Random(7)
def sample_path(truth):
# Simulated reasoning path: right 70% of the time, otherwise a scattered wrong answer.
if rng.random() < 0.7:
return rng.choice([f"{truth} credits", f" {truth}", f"{truth}.0"])
return f"{truth + rng.choice([-6, -3, 3, 5, 8])} credits"
def normalise(answer):
# TODO: strip spaces and the word "credits", and turn "42.0" into "42".
return answer
def vote(answers):
# TODO: return (most_common_answer, share) after normalising each answer.
return answers[0], 1.0
questions = [rng.randint(10, 90) for _ in range(300)]
single_right = vote_right = accepted = review = 0
for truth in questions:
single_right += normalise(sample_path(truth)) == str(truth)
best, share = vote([sample_path(truth) for _ in range(5)])
if share < 0.6:
review += 1
continue
accepted += 1
vote_right += best == str(truth)
print(f"single path accuracy: {single_right / len(questions):.0%}")
print(f"vote accuracy (accepted): {vote_right / max(1, accepted):.0%}")
print(f"routed to review: {review} of {len(questions)}")
Show a solution
import random
from collections import Counter
rng = random.Random(7)
def sample_path(truth):
# Simulated reasoning path: right 70% of the time, otherwise a scattered wrong answer.
if rng.random() < 0.7:
return rng.choice([f"{truth} credits", f" {truth}", f"{truth}.0"])
return f"{truth + rng.choice([-6, -3, 3, 5, 8])} credits"
def normalise(answer):
a = answer.replace("credits", "").strip()
try:
return str(int(float(a)))
except ValueError:
return a
def vote(answers):
counts = Counter(normalise(a) for a in answers)
best, n = counts.most_common(1)[0]
return best, n / len(answers)
questions = [rng.randint(10, 90) for _ in range(300)]
single_right = vote_right = accepted = review = 0
for truth in questions:
single_right += normalise(sample_path(truth)) == str(truth)
best, share = vote([sample_path(truth) for _ in range(5)])
if share < 0.6:
review += 1
continue
accepted += 1
vote_right += best == str(truth)
print(f"single path accuracy: {single_right / len(questions):.0%}")
print(f"vote accuracy (accepted): {vote_right / max(1, accepted):.0%}")
print(f"routed to review: {review} of {len(questions)}")