Skip to main content
← Back to techniques

Program-Aided Language Models (PAL)

Reasoning

Level 2 · Advanced reasoning

Have the model write code to compute the answer instead of calculating it directly in its reasoning — reduces arithmetic and logic errors.

Program-Aided Language Models asks the model to write code (typically Python) that computes the answer step by step, rather than performing the calculation directly inside its own reasoning. Because code execution is exact and language models are prone to arithmetic slips, offloading the computation to generated code — and actually running it — measurably reduces errors on math and logic-heavy tasks.

When to use it

Use it for tasks involving non-trivial arithmetic, counting, or multi-step logical computation, especially when using a tool that can actually execute the generated code.

When to avoid it

Avoid it if the AI tool you're using can't execute code — the technique only works if the code is actually run, not just read.

Advantages

  • Removes arithmetic/logic errors that come from a language model calculating "in its head"
  • The code itself is a transparent, checkable record of the method used
  • Particularly effective for tasks with many small calculation steps where errors compound

Disadvantages

  • Useless without actual code execution — many chat interfaces don't run generated code by default
  • Adds overhead for genuinely simple calculations

Examples

A store has 3 shelves. Each shelf holds 24 boxes, and each box contains 15 items. If 8% of items are defective, how many non-defective items are there in total?

Write code that computes the answer step by step, instead of calculating it directly in your reasoning. Show the code and its result.

Pairs well with

Try it

Fill in the placeholders below and see the compiled prompt update live.

What you want to achieve.

The material to work from.

26
Words
164
Characters
0/2
Placeholders filled
1 min
Reading time
Quality score6
  • Completeness0
  • Clarity0
  • Context0
  • Specificity0
  • Constraints0
  • Format0
  • Output0
  • Constraints note0
  • Success criteria0
  • Scope focus100
  • Verification step0
  • Negative example0
  • Confidence0
  • Placeholder syntax100
  • Markdown structure0
Suggestions
  • Fill in the remaining placeholders.
  • Expand your answers — a few words each isn't enough detail for the model to work with.
  • Add background context so the model understands the situation.
{{OBJECTIVE}} Input: {{INPUT}} Write code that computes the answer step by step, instead of calculating it directly in your reasoning. Show the code and its result.
AI Assistant

Jump to a page…

Navigation