Tree-of-thought (ToT) prompting is a technique in which a language model proposes several possible next steps for a problem, evaluates how promising each one is, and keeps exploring only the strongest branches, backtracking when a branch dead-ends. It differs from chain-of-thought prompting, which commits to a single line of reasoning from start to finish. ToT helps most on problems that need search or planning, and it costs noticeably more tokens than a single reasoning pass.
This article explains where the technique comes from, how the original method works, what the paper’s results actually show, and how to apply it at three levels of effort: one prompt in a chat window, a guided multi-turn session, and a small script.
Where tree-of-thought comes from
The method was introduced in the 2023 paper Tree of Thoughts: Deliberate Problem Solving with Large Language Models by Shunyu Yao, Dian Yu, Jeffrey Zhao, Izhak Shafran, Thomas L. Griffiths, Yuan Cao and Karthik Narasimhan. In the paper, a thought is a coherent piece of text that serves as an intermediate step toward a solution: one equation, a few words, or a short plan, depending on the task. The tree is made of these partial solutions, and the model is used both to grow the tree and to judge its branches.
The motivation is simple. A standard chain-of-thought answer is generated left to right, one token after another. If the model makes a poor choice early, every later step builds on it, and there is no built-in moment to stop and try something else. ToT adds that moment.
The four parts of the original method
The paper describes ToT as four design decisions you make for each problem type. Knowing them makes it much easier to write a ToT prompt that fits your task instead of copying a generic one.
- Thought decomposition. Decide how big one step is. In the paper, a step was one arithmetic line for the Game of 24, a few words for mini crosswords, and a paragraph-length plan for creative writing. A step should be small enough that the model can produce several distinct options, and large enough that each option can be judged.
- Thought generation. Either sample several independent continuations (useful when the space of options is wide, as in writing), or ask for several options in one prompt (useful when options are constrained, and it avoids duplicates).
- State evaluation. Either score each partial solution on its own, for example labelling it “sure”, “maybe” or “impossible”, or show the model several candidates and have it vote for the most promising.
- Search. Breadth-first search (BFS) keeps the best few candidates at each level. Depth-first search (DFS) follows the most promising branch, prunes branches judged hopeless, and backtracks when it gets stuck. The paper used BFS for the Game of 24 and creative writing, and DFS for crosswords.
What the results show, and what they do not
The headline result is from the Game of 24, a puzzle in which you combine four numbers with +, -, × and ÷ to reach 24. According to the paper’s abstract, GPT-4 with chain-of-thought prompting solved 4% of the test problems, while ToT reached 74%. The paper also reports gains on its two other tasks:
| Task (GPT-4, as reported by Yao et al.) | Chain-of-thought | Tree-of-thought |
|---|---|---|
| Game of 24, success rate | 4% | 74% |
| Mini crosswords, words correct | 15.6% | 60% |
| Creative writing, coherence score (1-10, GPT-4 judged) | 6.93 | 7.56 |
Those numbers need context before you apply them to your own work:
- It was a program, not a single prompt. The paper ran ToT as code that called the model many times and managed the tree. The one-prompt versions people use in chat are approximations and were not what produced the 74%.
- The tasks were chosen to need search. The authors note that on tasks GPT-4 already handled well, deliberate search was likely unnecessary, and they report only small differences on common reasoning benchmarks.
- It was more expensive. For the Game of 24 the paper reports roughly $0.74 per problem for ToT, against about $0.47 for running chain-of-thought 100 times and picking the best. For creative writing, ToT used around five times the completion tokens of chain-of-thought.
- The base model mattered. With GPT-3.5 instead of GPT-4, the paper’s Game of 24 success rate fell to 19%; the authors point to weaker generation of good candidate steps as the cause.
- The models are from 2023. Today’s reasoning models already spend extra tokens thinking before they answer. Whether an explicit ToT structure still adds accuracy on top of that depends on the task, and should be checked on your own problems rather than assumed. Our guide to AI reasoning models and extended thinking covers how that built-in reasoning works.
Tree-of-thought compared with related techniques
ToT sits in a family of techniques that spend more computation to get a better answer. The main difference is when, and how, alternatives are compared.
| Technique | How many paths | When paths are compared | Can it backtrack? |
|---|---|---|---|
| Chain-of-thought | One | Never | No |
| Self-consistency | Several complete chains | At the end, by majority vote on the answer | No |
| Tree-of-thought | Several partial paths | At every step | Yes |
| Chain-of-verification | One draft | After drafting, by checking claims | Revises, does not branch |
Self-consistency is the cheapest step up from chain-of-thought when a question has one checkable answer. ToT is worth the extra cost when the difficulty lies in choosing the right path through intermediate steps.
A worked example: one Game of 24 problem
To see the mechanics, take the numbers 4, 9, 10 and 13. The trace below is an illustration of the BFS procedure written by hand, not model output.
- Generate. Propose several first steps: 13 – 9 = 4 (left: 4, 4, 10); 10 – 4 = 6 (left: 6, 9, 13); 9 + 13 = 22 (left: 4, 10, 22); 4 × 10 = 40 (left: 9, 13, 40).
- Evaluate. Judge whether each remaining set can still reach 24. “4, 4, 10” looks promising (10 – 4 = 6, 6 × 4 = 24): sure. “6, 9, 13” is unclear: maybe. “4, 10, 22” and “9, 13, 40” seem hard to bring to exactly 24: label them impossible.
- Keep the best. Carry “4, 4, 10” and “6, 9, 13” to the next level; drop the rest.
- Expand. From “4, 4, 10”: 10 – 4 = 6, leaving 4 and 6. Then 4 × 6 = 24. Solved: (10 – 4) × (13 – 9) = 24.
A single chain-of-thought pass could just as easily have started with 4 × 10 = 40 and then spent the rest of its answer forcing a bad position. The evaluation step is what lets ToT abandon that branch early. It is also the weak point: if the evaluator wrongly marks a good branch as impossible, the search never returns to it.
Level 1: a single prompt you can use in any chat
A widely shared one-prompt approximation, credited to Dave Hulbert and listed in the Prompt Engineering Guide’s ToT page, asks the model to imagine three experts who each write one step at a time and drop out when they realise they are wrong. The version below keeps that idea but makes the generate, evaluate and prune stages explicit, so you can see each one in the output.
Solve the problem below by exploring several approaches, not just one.
<problem>
[your problem, with all constraints]
</problem>
Round 1
- Propose 3 genuinely different first steps or approaches. Label them A, B, C.
- For each, rate it: sure / maybe / impossible, with one sentence of reasoning
checked against the constraints.
Round 2
- Drop anything rated impossible.
- Develop each remaining approach by one more step, then rate again.
Repeat until one approach reaches a complete solution or all are dropped.
If all are dropped, go back to the last rejected option you were least sure about
and try it.
Finish with:
- The final solution
- Why it satisfies every constraint (check each one)
- The strongest approach you rejected and why it lost
Why it is written this way: “genuinely different” pushes against three near-identical options; rating against the constraints gives the evaluation step something concrete to check; the “go back” line is a rough stand-in for backtracking; and asking for the rejected approach makes the comparison visible so you can spot a bad pruning decision. The limitation is that all of this happens in one response, so the model can still talk itself into its first idea. That makes the next level more reliable.
Level 2: a guided multi-turn session
Splitting the stages across separate messages lets you act as the evaluator, or at least review the model’s evaluation before it continues. This suits planning and design problems where your judgment matters more than an arithmetic check.
Message 1
Here is the problem: [problem and constraints].
Give me 3 distinct approaches in 3-4 sentences each. Do not develop any of them yet.
Message 2
Evaluate each approach against these criteria: [criteria, e.g. cost, risk,
time to deliver]. For each criterion say which approach is strongest and
which is weakest. Then rank the approaches. Note anything you are unsure about.
Message 3 (after you review the ranking)
Develop approach [X] into concrete steps. Stop at the first step where
you find a serious problem and tell me what it is.
Message 4 (only if a problem appears)
Go back to approach [Y]. Develop it to the same level of detail,
then compare the two developed versions.
Each message is one node of the tree, and you decide where to branch. This is similar in spirit to prompt chaining, with the difference that the chain is allowed to go back.
Level 3: a small BFS script
For problems where you can automate the evaluation, a short loop gets closest to the paper’s setup. The sketch below is provider-agnostic: llm() stands for whatever function sends a prompt to your model and returns text. It is a starting point, not production code.
def propose(state, k=3):
prompt = (f"Problem: {PROBLEM}\nProgress so far:\n{state}\n"
f"Propose {k} different next steps, one per line.")
return [s.strip() for s in llm(prompt).splitlines() if s.strip()][:k]
def evaluate(state):
prompt = (f"Problem: {PROBLEM}\nPartial solution:\n{state}\n"
"Can this still reach a valid solution? "
"Answer with one word: sure, maybe, or impossible.")
word = llm(prompt).strip().lower()
return {"sure": 2, "maybe": 1}.get(word, 0)
def tree_of_thought(depth=3, breadth=2):
frontier = [""]
for _ in range(depth):
candidates = []
for state in frontier:
for step in propose(state):
new_state = state + step + "\n"
candidates.append((evaluate(new_state), new_state))
candidates = [c for c in candidates if c[0] > 0]
candidates.sort(key=lambda c: c[0], reverse=True)
frontier = [s for _, s in candidates[:breadth]]
if not frontier:
return None
return frontier[0]
Likely problems and fixes:
- The evaluator returns a sentence instead of one word. The parser then scores it as 0 and prunes everything. Use structured output or a stricter instruction, and log raw replies while testing.
- All proposals are near-duplicates. Ask for steps that differ in method, or sample with a higher temperature for the proposal call only.
- Costs grow fast. Calls per run are roughly depth × breadth × (proposals + evaluations). With the defaults above that is already a few dozen calls. Start small and cap it.
- A programmatic check exists. If you can verify a step in code (arithmetic, unit tests, a schema), use the code as the evaluator. It is cheaper and more reliable than asking the model.
When tree-of-thought is worth it
ToT makes sense when three conditions hold: the problem has several plausible first moves, a wrong early move is costly, and partial progress can be judged before the end. Good candidates include puzzles and constraint problems, multi-step plans such as a migration or a schedule with dependencies, debugging where several causes fit the symptoms, and design choices with explicit trade-offs.
It is overkill for factual lookups, single-step tasks, summaries, routine rewriting, and anything a current model already answers reliably with a direct prompt. In those cases the extra branches add cost and latency without a better answer. If you are not sure, run the same problems with a plain prompt, with self-consistency, and with ToT, and compare accuracy against cost.
Common questions
Do I need special tools or an API to use tree-of-thought?
No. The paper used custom code to run the search, but the Level 1 and Level 2 approaches work in any chat interface. Code becomes useful when you want real backtracking, automated evaluation, or to run the method over many problems.
Why does exploring several paths help?
Because the model gets to compare options before committing. In a single chain, an early mistake becomes the premise for every later step. Evaluating partial paths gives the model a chance to notice a failing branch and switch, which is how people tend to solve hard puzzles too.



