---
title: "Program of Thoughts Prompting"
source: "https://systems-analysis.info/eng/Program_of_Thoughts_Prompting"
wiki: "systems-analysis.info/eng"
article: "Program_of_Thoughts_Prompting"
language: "en"
categories:
  - "Category:English"
  - "Category:Large language models"
  - "Category:Machine learning"
  - "Category:Prompt engineering"
  - "Category:Technology"
revision_id: 308
wiki_created_at: 2026-09-06T22:20:20Z
wiki_modified_at: 2026-09-06T22:20:20Z
downloaded_at: 2026-09-07T22:22:36Z
---

# Program of Thoughts Prompting

**Program of Thoughts Prompting** (**PoT**) is a prompt engineering method for [large language models (LLMs)](https://systems-analysis.info/eng/Large_language_model "Large language model") where the model generates program code as intermediate steps for solving a problem, instead of a textual explanation<sup>[\[1\]](https://systems-analysis.info/eng/Program_of_Thoughts_Prompting#cite_note-pot_paper-1)</sup>. This approach allows for the separation of logical reasoning from mathematical computations: the language model formulates a solution plan as a program (e.g., in Python), and the calculations are executed by an external, deterministic code interpreter.

The method was proposed in 2022 by a group of researchers led by **Wenhu Chen** and is primarily aimed at tasks of a numerical or logical nature (mathematical problems, financial calculations), where traditional reasoning methods like Chain-of-Thought struggled with computational accuracy<sup>[\[1\]](https://systems-analysis.info/eng/Program_of_Thoughts_Prompting#cite_note-pot_paper-1)</sup>.

## Background and Concept

### Limitations of Chain-of-Thought

The PoT method is an evolution of the **Chain-of-Thought (CoT)** idea, which was previously the primary approach for improving the logical inference of LLMs<sup>[\[2\]](https://systems-analysis.info/eng/Program_of_Thoughts_Prompting#cite_note-cot_paper-2)</sup>. In the CoT method, the model generates a sequence of intermediate steps in natural language. Despite significantly improving reasoning quality, this approach has a fundamental limitation: the model performs both the logic and the calculations themselves in textual form. This often leads to inaccurate arithmetic operations, rounding errors, and other inaccuracies, as language models are not inherently precise calculators.

### Core Idea of Program of Thoughts

The core idea of PoT is to delegate computations to an external system (a code interpreter), while requiring the language model only to formalize the solution plan as an executable program<sup>[\[1\]](https://systems-analysis.info/eng/Program_of_Thoughts_Prompting#cite_note-pot_paper-1)</sup>. The model acts as a "programmer" rather than a "calculator."

The process works as follows:

1.  The model receives a task as input (e.g., a math word problem).
2.  Instead of textual reasoning, it generates a script in a programming language (e.g., **Python**) that solves the task.
3.  The generated code is passed to an external interpreter, which executes it.
4.  The result of the code execution is the final answer.

Thus, complex and precise calculations (operations with large numbers, calls to specialized libraries) are performed not by the model itself but by the program, ensuring determinism and high accuracy<sup>[\[3\]](https://systems-analysis.info/eng/Program_of_Thoughts_Prompting#cite_note-pot_ministry_ai-3)</sup>.

## Implementation and Use of Libraries

In the implementation of PoT, the LLM's ability to generate correct and efficient code is key. The authors of the approach used the **OpenAI Codex** model, which was specifically trained on programming tasks. The PoT approach allows the model to leverage external libraries, significantly expanding the class of problems it can solve. For example, when solving symbolic mathematics problems, the model can generate code that uses the **SymPy** library to solve equations analytically, which is beyond the capabilities of purely language-based methods<sup>[\[1\]](https://systems-analysis.info/eng/Program_of_Thoughts_Prompting#cite_note-pot_paper-1)</sup>.

A prompt for PoT can be provided in two modes:

- **Few-shot**: The prompt contains several examples of "question-solution program" pairs.
- **Zero-shot**: The prompt provides only an instruction describing the task, without examples.

Even in *zero-shot* mode, PoT demonstrates high effectiveness due to the explicit structure that the model is required to generate<sup>[\[4\]](https://systems-analysis.info/eng/Program_of_Thoughts_Prompting#cite_note-pot_learnprompting-4)</sup>.

## Results and Effectiveness

The PoT method has demonstrated a significant improvement in the quality of solutions for tasks requiring multi-step numerical reasoning. In the original paper, it was tested on eight datasets of mathematical and financial problems, including **GSM8K**, **AQUA**, **SVAMP**, **FinQA**, and others.

- **Improved Accuracy**: In all cases, PoT outperformed the baseline CoT approach. On average, a relative gain of **~12%** in the proportion of correct solutions was achieved.
  - On the popular **GSM8K** math dataset, the model's accuracy with PoT reached **71.6%**, compared to **63.1%** with CoT.
  - In financial tasks, the improvement was even more substantial: on the **FinQA** dataset, accuracy increased from **40.4%** (CoT) to **64.5%** (PoT)<sup>[\[1\]](https://systems-analysis.info/eng/Program_of_Thoughts_Prompting#cite_note-pot_paper-1)</sup>.

<!-- -->

- **Combination with Self-Consistency**: The effectiveness of PoT can be further enhanced when combined with the **self-consistency** method. In this case, the model generates several independent solution programs, and the final answer is chosen by a "majority vote" from their execution results. Combined with *self-consistency*, PoT established a new **state-of-the-art** at the time of publication for all tested mathematical and financial benchmarks<sup>[\[1\]](https://systems-analysis.info/eng/Program_of_Thoughts_Prompting#cite_note-pot_paper-1)</sup>.

## Advantages and Limitations

### Advantages

- **Computational Accuracy**: The main advantage. Executing arithmetic operations with an external interpreter eliminates rounding errors and inaccuracies inherent in LLMs.
- **Ability to Use Libraries**: The model can leverage powerful external libraries (e.g., for symbolic computation, statistical analysis, or date manipulation), solving problems that were previously inaccessible.
- **Interpretability and Debugging**: Program code provides a formal and structured representation of the solution logic, making it easier to verify and debug compared to natural language reasoning.
- **Versatility**: The approach is effective in both *few-shot* and *zero-shot* modes and is applicable across different domains (mathematics, finance, science).

### Limitations

- **Security**: Executing generated code in an external interpreter creates security risks. The model could theoretically generate malicious code (e.g., to delete files). Therefore, practical application of PoT requires an isolated execution environment (a *sandbox*) and careful code filtering<sup>[\[4\]](https://systems-analysis.info/eng/Program_of_Thoughts_Prompting#cite_note-pot_learnprompting-4)</sup>.
- **Limited Scope of Applicability**: The method is most effective for problems that can be clearly formalized as an algorithm. For tasks requiring an understanding of language nuances, common sense, or a creative approach, the direct application of PoT is challenging.
- **Dependence on Code Quality**: The method's effectiveness directly depends on the LLM's ability to generate syntactically correct and logically sound code.

## Related Approaches

The idea of using code to improve LLM reasoning has been developed in other similar approaches as well.

- **Program-Aided Language Models (PAL)**: A method proposed almost concurrently with PoT, which also uses Python code generation to solve problems<sup>[\[5\]](https://systems-analysis.info/eng/Program_of_Thoughts_Prompting#cite_note-pal_guide-5)</sup>. Conceptually, PAL and PoT are very similar and confirm the effectiveness of the "reasoning via code" strategy.
- **Tree of Thoughts (ToT)**: A more complex method that involves generating and exploring a "tree" of possible solution steps, which is an extension of the linear "chain" of thought concept. PoT can be used within the nodes of this tree to test hypotheses.

## External links

- <a href="https://arxiv.org/abs/2211.12588" class="external text" rel="nofollow">Original scientific paper on Program of Thoughts Prompting</a>
- <a href="https://learnprompting.org/docs/advanced/decomposition/program_of_thoughts" class="external text" rel="nofollow">Guide to PoT on the Learn Prompting portal</a>

## Bibliography

- Chen, W. et al. (2023). *Program of Thoughts Prompting: Disentangling Computation from Reasoning for Numerical Reasoning Tasks*. <a href="https://arxiv.org/abs/2211.12588" class="external text" rel="nofollow">arXiv:2211.12588</a>.
- Wei, J. et al. (2022). *Chain of Thought Prompting Elicits Reasoning in Large Language Models*. <a href="https://arxiv.org/abs/2201.11903" class="external text" rel="nofollow">arXiv:2201.11903</a>.
- Wang, X. et al. (2022). *Self-Consistency Improves Chain of Thought Reasoning in Language Models*. <a href="https://arxiv.org/abs/2203.11171" class="external text" rel="nofollow">arXiv:2203.11171</a>.
- Gao, L. et al. (2022). *PAL: Program-Aided Language Models*. <a href="https://arxiv.org/abs/2211.10435" class="external text" rel="nofollow">arXiv:2211.10435</a>.
- Cobbe, K. et al. (2021). *Training Verifiers to Solve Math Word Problems*. <a href="https://arxiv.org/abs/2110.14168" class="external text" rel="nofollow">arXiv:2110.14168</a>.
- Chen, Z. et al. (2021). *FinQA: A Dataset of Numerical Reasoning over Financial Data*. <a href="https://arxiv.org/abs/2109.00122" class="external text" rel="nofollow">arXiv:2109.00122</a>.
- Zhu, F. et al. (2021). *TAT-QA: A Question Answering Benchmark on a Hybrid of Tabular and Textual Content in Finance*. <a href="https://arxiv.org/abs/2105.07624" class="external text" rel="nofollow">arXiv:2105.07624</a>.
- Patel, A. et al. (2021). *Are NLP Models Really Able to Solve Simple Math Word Problems? (Introducing SVAMP)*. <a href="https://arxiv.org/abs/2103.07191" class="external text" rel="nofollow">arXiv:2103.07191</a>.
- Xu, F. et al. (2023). *RECOMP: Improving Retrieval-Augmented LMs with Compression and Selective Augmentation*. <a href="https://arxiv.org/abs/2310.04408" class="external text" rel="nofollow">arXiv:2310.04408</a>.
- Mu, J. et al. (2023). *Learning to Compress Prompts with Gist Tokens*. <a href="https://arxiv.org/abs/2304.08467" class="external text" rel="nofollow">arXiv:2304.08467</a>.

## References

1.  <span id="cite_note-pot_paper-1">↑ <sup>[1.0](https://systems-analysis.info/eng/Program_of_Thoughts_Prompting#cite_ref-pot_paper_1-0)</sup> <sup>[1.1](https://systems-analysis.info/eng/Program_of_Thoughts_Prompting#cite_ref-pot_paper_1-1)</sup> <sup>[1.2](https://systems-analysis.info/eng/Program_of_Thoughts_Prompting#cite_ref-pot_paper_1-2)</sup> <sup>[1.3](https://systems-analysis.info/eng/Program_of_Thoughts_Prompting#cite_ref-pot_paper_1-3)</sup> <sup>[1.4](https://systems-analysis.info/eng/Program_of_Thoughts_Prompting#cite_ref-pot_paper_1-4)</sup> <sup>[1.5](https://systems-analysis.info/eng/Program_of_Thoughts_Prompting#cite_ref-pot_paper_1-5)</sup> Chen, W. et al. "Program of Thoughts Prompting: Disentangling Computation from Reasoning for Numerical Reasoning Tasks". *arXiv:2211.12588*, 2023. <a href="https://arxiv.org/abs/2211.12588" class="external autonumber" rel="nofollow">[1]</a></span>
2.  <span id="cite_note-cot_paper-2">[↑](https://systems-analysis.info/eng/Program_of_Thoughts_Prompting#cite_ref-cot_paper_2-0) Wei, J. et al. "Chain-of-Thought Prompting Elicits Reasoning in Large Language Models". *arXiv:2201.11903*, 2022. <a href="https://arxiv.org/abs/2201.11903" class="external autonumber" rel="nofollow">[2]</a></span>
3.  <span id="cite_note-pot_ministry_ai-3">[↑](https://systems-analysis.info/eng/Program_of_Thoughts_Prompting#cite_ref-pot_ministry_ai_3-0) "Program of Thoughts: Everything You Need to Know". *The Ministry of AI*. <a href="https://medium.com/@ThePromptIndex/program-of-thoughts-everything-you-need-to-know-7ebf2cb9d59c" class="external autonumber" rel="nofollow">[3]</a></span>
4.  <span id="cite_note-pot_learnprompting-4">↑ <sup>[4.0](https://systems-analysis.info/eng/Program_of_Thoughts_Prompting#cite_ref-pot_learnprompting_4-0)</sup> <sup>[4.1](https://systems-analysis.info/eng/Program_of_Thoughts_Prompting#cite_ref-pot_learnprompting_4-1)</sup> "Program of Thoughts Prompting: Enhancing Accuracy in Reasoning and Computation". *Learn Prompting*. <a href="https://learnprompting.org/docs/advanced/decomposition/program_of_thoughts" class="external autonumber" rel="nofollow">[4]</a></span>
5.  <span id="cite_note-pal_guide-5">[↑](https://systems-analysis.info/eng/Program_of_Thoughts_Prompting#cite_ref-pal_guide_5-0) "PAL (Program-Aided Language Models)". *Prompt Engineering Guide*. <a href="https://www.promptingguide.ai/techniques/pal" class="external autonumber" rel="nofollow">[5]</a></span>
