ModelRefs / Automatic Prompt Engineering (APE) — AI Glossary
Automatic Prompt Engineering (APE) — AI Glossary
Using an LLM to generate and evaluate candidate instructions, selecting the highest-performing prompt automatically. Also called APE or prompt optimization.
Overview
APE (Zhou et al. 2022) frames prompt optimization as a program synthesis problem: generate candidate instruction variants, evaluate each on a held-out set, keep the best. Extensions (OPRO, ProTeGi, DSPy) add iterative refinement and gradient-free optimization. Reduces manual prompt engineering effort for high-traffic production prompts.
Reference details
| Topic | prompting |
|---|---|
| Also known as | APE, prompt optimization |
| Last reviewed | 2026-06-24 |
Related terms
How it works
- Prompt optimisation is framed as search: propose candidate instructions, score each against a dataset, keep the best. The framing is what makes it automatable at all.
- Candidates are generated by a model, either from a task description or by inferring an instruction from input-output examples, which is cheaper and more diverse than human authoring.
- Each candidate is evaluated on a scoring set, and that evaluation is where essentially all the compute goes — the proposal step is one call and the scoring step is one call per example per candidate.
- Iterative variants feed the scores back, asking the model to propose refinements of what worked, which converges faster than sampling independent candidates.
- The decisive methodological requirement is a held-out set. Selecting the maximum of many noisy estimates biases the winner's measured score upward, so the reported gain must be confirmed on data the search never saw.
- The output is a prompt, not a model, which is what makes it cheap to deploy and also means it must be re-run whenever the underlying model changes.
Example: How much of the winner's apparent gain is selection noise
Score 50 candidate prompts on 200 examples. The compute is 50 x 200 = 10,000 model calls per round, and five rounds is 50,000 calls — the real cost of the method. Now the statistical trap. Each candidate's score is an estimate with standard error sqrt(p(1-p)/n), so near p = 0.5 that is sqrt(0.25 / 200) = 0.0354, about 3.5 points. Taking the maximum of 50 such estimates does not return the best candidate; it returns the candidate with the luckiest sample. The expected maximum of 50 independent draws sits roughly 2.25 standard deviations above the mean, so about 2.25 x 3.5 = 7.9 points of the winner's apparent advantage is selection noise rather than a real improvement. A measured 10-point gain on the scoring set is therefore consistent with a true gain of around 2 points. Evaluating the winner on a held-out set of 200 fresh examples removes that bias entirely, because the selection has already happened and the new estimate is unbiased — which is why the held-out check is not good practice but the only thing that distinguishes a result from an artefact of searching.
Commonly confused with
Automatic prompt engineering optimises instructions; it is not the same as selecting examples, and a system can do both independently. Instruction optimisation searches over the wording of the task description. Exemplar selection chooses which demonstrations to include, either fixed or retrieved per query. The two interact — the best instruction depends on which examples accompany it — which is why frameworks that optimise both jointly outperform doing either alone, and why a reported gain from one should not be attributed to prompt optimisation generally.
When to use it
Reach for it when:
- High-traffic production prompts, where a small accuracy gain is amortised over enough requests to pay for the search.
- After a model change, where a prompt tuned for the previous model is now tuned for the wrong thing.
- Tasks with a cheap automatic scoring function, since the search cost is dominated by the number of evaluations.
- With a held-out confirmation set, without which the reported improvement is partly the search finding noise.
Reach for something else when:
- Low-traffic prompts, where the search costs more than the lifetime value of the improvement.
- Without a held-out set, where selecting the best of many noisy estimates reliably overstates the gain.
- On small scoring sets, where the per-candidate standard error is large enough that the search mostly ranks sampling luck.
- When the problem is the task definition rather than its wording, which no amount of rephrasing addresses.
Continue your research
Use these connected ModelRefs sections to compare alternatives, inspect implementation paths, and review the evidence and governance boundaries relevant to Automatic Prompt Engineering (APE) — AI Glossary.
Frequently asked questions
What is Automatic Prompt Engineering (APE)?
Using an LLM to generate and evaluate candidate instructions, selecting the highest-performing prompt automatically.
Is Automatic Prompt Engineering (APE) the same as APE?
Yes — APE, prompt optimization are common aliases for Automatic Prompt Engineering (APE).
What concepts are related to Automatic Prompt Engineering (APE)?
Closely related concepts include dspy, prompt template, calibration.