P

Program of Thought: Definition and Examples

Prompting technique where the model generates executable code to solve a reasoning problem, instead of producing a natural language chain of thought.

Full definition

Program of Thought (PoT) is an advanced prompting method introduced by Chen et al. in 2022, which separates reasoning from computation execution. Rather than asking the model to solve a problem step by step in natural language (as in Chain of Thought), it is asked to generate a program — typically in Python — that encodes the solution logic. This program is then executed by an external interpreter to obtain the final answer.

The intuition behind this approach is simple: language models are excellent at understanding a problem and formulating a solution strategy, but they frequently make arithmetic or logical calculation errors. By delegating execution to a code interpreter, we combine the best of both worlds — the LLM's linguistic understanding and the computational precision of an execution engine.

PoT has proven particularly effective on math reasoning benchmarks like GSM8K and AQuA, where it significantly outperforms classic Chain of Thought. It also excels in problems involving iterations, complex data structures, or financial calculations — areas where natural language reasoning reaches its limits.

This technique is part of a broader movement to augment LLMs with external tools. It is now natively integrated into several AI agent frameworks and constitutes one of the foundations of the "code as reasoning" approach gaining popularity in the community.

Etymology

The term "Program of Thought" was introduced in the research paper "Program of Thoughts Prompting: Disentangling Computation from Reasoning for Numerical Reasoning Tasks" published by Wenhu Chen et al. in 2022. The name directly echoes "Chain of Thought" by replacing the textual chain with a computer program, thereby highlighting the shift from verbal reasoning to programmatic reasoning.

Concrete examples

Solving a complex math problem

Solve this problem by writing a Python program.

Problem: A store offers a 15% discount on all items. If a customer buys 3 shirts at €45 each and 2 pants at €62 each, how much do they pay after the discount and with 20% VAT?

Write the Python code to calculate the final amount.

Reasoning about dates and durations

Write a Python program to solve this problem:

Marie was born on March 14, 1990. She started her first job exactly 23 years and 147 days after her birth. What day of the week was it?

Financial analysis with iterations

Generate a Python program to answer this question:

An investor puts €10,000 at a compound interest rate of 4.5% per year. Each year, they add €2,000. After how many years does their capital exceed €50,000?

Practical usage

To apply Program of Thought, explicitly ask the model to generate executable code rather than a natural language answer. Formulate your prompt with an instruction like "Write a Python program to solve this problem" and execute the generated code in a secure environment. This technique is particularly recommended for any problem involving calculations, iterations, or structured data manipulation.

Related concepts

Chain of ThoughtCode InterpreterTool UsePAL (Program-Aided Language Models)ReAct

FAQ

What is the difference between Program of Thought and Chain of Thought?
Chain of Thought (CoT) asks the model to reason step by step in natural language, while Program of Thought (PoT) asks it to express that reasoning as executable code. CoT keeps the entire process in text, which makes it prone to calculation errors. PoT delegates computations to an interpreter, ensuring computational accuracy while retaining the model's ability to understand and structure the problem.
Do you need to know how to program to use Program of Thought?
No, you don't need to know how to program to use this technique. The model generates the code for you, and many environments (like ChatGPT or Claude's built-in Code Interpreters) automatically execute the produced code. However, a basic understanding of code can help you verify the logic of the proposed solution and formulate more precise prompts.
In which cases is Program of Thought more effective than other techniques?
PoT excels in numerical and mathematical reasoning tasks, date and duration manipulation, problems requiring loops or iterations, and structured data analysis. For purely linguistic tasks like creative writing, sentiment analysis, or text summarization, classic Chain of Thought remains more suitable because these tasks do not benefit from code execution.

See also

How to use this prompt

  1. Copy the prompt with the button above.
  2. Paste it into ChatGPT, Claude or your favorite AI assistant.
  3. Replace the bracketed variables with your details, then refine the result.

About Prompt Guide

Prompt Guide is a free library of 2500+ ready-to-use prompts for ChatGPT, Claude and other AIs, with guides to learn prompting and tools to build and optimize your own prompts.

More definitions

Get new prompts every week

Join our newsletter.