What is automatic prompt optimisation?
Automatic prompt optimisation is a family of methods searching for the best prompt for a task by having a language model propose candidate prompts, scoring them on labelled examples and iteratively refining the best, instead of manual trial and error.
Unlike prompt tuning, which learns continuous vectors added to the model's input via gradients and yields no readable text, automatic prompt optimisation produces readable natural language prompts and needs no access to model weights or gradients.
- Topic
- Prompts, context, reasoning and generation
- Also known as
- Automatic prompt engineering, APO
How automatic prompt optimisation works
- A small labelled example set and a success metric are prepared for the task.
- A language model proposes new candidate prompts from the current prompt and examples.
- Candidates run and are scored on the examples; some methods turn errors into natural language critiques used to revise the prompt.
- The best candidates move to the next round until the budget runs out; the result is validated on a separate set.
In more detail
Compound AI pipelines and DSPy and TextGrad
APO evolved from tuning single instructions (APE, OPRO) to compiling entire multi-stage AI pipelines, including RAG queries, tool descriptions and few-shot demonstrations, using frameworks such as DSPy (e.g., MIPROv2) and TextGrad.
Search methods: evolutionary search, textual gradients and Bayesian optimisation
Optimisation strategies include evolutionary/genetic mutation (such as EvoPrompt), textual gradient descent where an LLM critiques errors in natural language (such as ProTeGi and TextGrad) and Bayesian surrogate search over joint instruction and demonstration candidates.
Fragility across model versions and training data leakage
Automated optimisers can inadvertently copy sensitive details from training examples into the resulting prompt's rules or few-shot examples, creating privacy leakage risks. Optimised prompts are often brittle across model upgrades or quantisation changes, requiring re-validation whenever the underlying model changes.
Commonly confused terms
| Term | How it differs |
|---|---|
| Manual prompt engineering | Manual prompt engineering relies on human intuition and iterative trial and error, whereas APO automates candidate generation, evaluation and refinement against a quantitative metric and validation set. |
| Fine-tuning | Fine-tuning (full or LoRA) updates model weights to internalise new behaviours or domain knowledge, whereas APO leaves model weights untouched and only searches for better input instructions and few-shot examples. |
Why automatic prompt optimisation matters for on-premises AI
Manual prompt tuning is slow. A study proposing automatic prompt generation showed generated instructions beat the prior baseline by a large margin on 24 tasks and matched or beat human-written ones. Another, using a language model as optimiser, reported its best prompts beat human-designed ones by up to 8% on a maths benchmark and up to 50% on a hard task set. The risk is overfitting a small example set.
An insurer automatically refines its prompt classifying claim emails using labelled examples; it tests the best candidate on a held-out validation set and saves the new version to its prompt store.
Common questions
Does automatic prompt optimisation change model weights?
No. It changes only the prompt text and needs no access to weights or gradients.
What does automatic prompt optimisation need?
Representative labelled examples, a clear success metric, a model to propose candidates and a separate set to validate the result.
Related terms
- Prompt engineering
- Prompt tuning
- Prompt template
- Evaluation dataset
- Hyperparameter tuning
- Prompt versioning
Sources
- Zhou et al., Large Language Models Are Human-Level Prompt Engineers, 2022
- Pryzant et al., Automatic Prompt Optimization with "Gradient Descent" and Beam Search, 2023
- Yang et al., Large Language Models as Optimizers, 2023
In the glossary: Glossary, A to C