prompt-eng

Program-Aided Language Model (PAL)

A Program-Aided Language Model (PAL) is a prompting pattern where, instead of computing an answer in prose, the model writes a short program — usually Python — whose execution produces the result. Introduced by Gao et al. (2023), PAL splits the work: the LLM reads the problem and expresses the logic as code, while a plain interpreter does the actual arithmetic and control flow deterministically. This sidesteps a core weakness — language models are unreliable calculators but competent code authors — and the same idea appears as Program-of-Thoughts. It matters wherever answers must be exact: pricing math, date and timezone logic, unit conversions, data aggregations, or anything you would not trust to token-by-token 'mental math.' For builders, the practical shape is a sandboxed code-execution step wired after generation, returning the program's output as the answer. Caveats: you must run untrusted code safely (isolated sandbox, timeouts, no network), and the model can still write buggy logic — so validate results and log the generated code for debugging.

Related terms

More Prompt Engineering terms