Implementation:Princeton nlp Tree of thought llm Prompt Templates
| Knowledge Sources | |
|---|---|
| Domains | Prompt_Design, NLP, LLM_Reasoning |
| Last Updated | 2026-02-14 03:30 GMT |
Overview
Concrete tool for defining few-shot prompt templates as module-level string variables that structure all LLM interactions in the Tree of Thoughts framework.
Description
Prompt templates are Python string constants defined in dedicated modules under src/tot/prompts/. Each task has its own prompts file exporting template variables that are imported via from tot.prompts.{task} import * in the corresponding task class. Templates use Python's .format(input=...) for variable substitution.
The framework includes three reference prompt modules:
- game24.py (134 lines): 5-shot standard, 5-shot CoT, 1-shot propose, 8-shot value, 6-shot value-last-step.
- text.py (25 lines): Short standard, CoT, vote, compare, and score prompts for creative writing.
- crosswords.py (326 lines): Elaborate prompts with 5-shot examples for crossword solving.
Usage
Create a new prompts file when adding a new task. Define module-level string variables for each prompt type needed by the task's generation/evaluation strategy. Import them via wildcard import in the task class.
Code Reference
Source Location
- Repository: tree-of-thought-llm
- File: src/tot/prompts/game24.py (Lines 1-134), src/tot/prompts/text.py (Lines 1-25), src/tot/prompts/crosswords.py (Lines 1-326)
Signature
# Game of 24 prompt templates (src/tot/prompts/game24.py)
# 5-shot IO prompt
standard_prompt = '''Use numbers and basic arithmetic operations (+ - * /) to obtain 24.
Input: 4 4 6 8
Answer: (4 + 8) * (6 - 4) = 24
...
Input: {input}
'''
# 5-shot CoT prompt with step-by-step traces
cot_prompt = '''Use numbers and basic arithmetic operations...
Input: 4 4 6 8
Steps:
4 + 8 = 12 (left: 4 6 12)
...
Input: {input}
'''
# 1-shot structured proposal prompt
propose_prompt = '''Input: 2 8 8 14
Possible next steps:
2 + 8 = 10 (left: 8 10 14)
...
Input: {input}
Possible next steps:
'''
# 8-shot value assessment prompt
value_prompt = '''Evaluate if given numbers can reach 24 (sure/likely/impossible)
...
{input}
'''
# 6-shot last-step validation prompt
value_last_step_prompt = '''...
Input: {input}
Answer: {answer}
Judge:'''
Import
from tot.prompts.game24 import *
# Imports: standard_prompt, cot_prompt, propose_prompt, value_prompt, value_last_step_prompt
from tot.prompts.text import *
# Imports: standard_prompt, cot_prompt, vote_prompt, compare_prompt, score_prompt
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| {input} | str | Yes | Problem input (e.g., "1 2 3 4" for Game24, text instruction for Text) |
| {answer} | str | Conditional | Candidate answer (only for value_last_step_prompt) |
Outputs
| Name | Type | Description |
|---|---|---|
| Formatted prompt | str | Complete prompt string ready for LLM API call |
Usage Examples
Using Game of 24 Prompts
from tot.prompts.game24 import standard_prompt, propose_prompt, value_prompt
# IO prompt
io_prompt = standard_prompt.format(input="1 2 3 4")
# "Use numbers and basic arithmetic operations...Input: 1 2 3 4\n"
# Propose prompt (expects "Possible next steps:" response)
prop_prompt = propose_prompt.format(input="3 4")
# "Input: 2 8 8 14\nPossible next steps:\n...\nInput: 3 4\nPossible next steps:\n"
# Value prompt
val_prompt = value_prompt.format(input="3 4")
# "Evaluate if given numbers can reach 24...\n3 4\n"
Creating Prompts for a New Task
# src/tot/prompts/my_task.py
# 3-shot standard prompt
standard_prompt = '''Solve the puzzle.
Input: example1
Answer: solution1
Input: example2
Answer: solution2
Input: example3
Answer: solution3
Input: {input}
'''
# 1-shot propose prompt
propose_prompt = '''Given the current state, list possible next moves.
State: example_state
Possible moves:
move1
move2
move3
State: {input}
Possible moves:
'''
# Value assessment prompt
value_prompt = '''Is this state solvable? (sure/likely/impossible)
{input}
'''