Automatic prompt engineer (APE) is a method that treats the writing of an instruction as a search problem solved by a language model: one model proposes many candidate prompts from a few input-output examples, the candidates are scored on held-out data, and the best-performing instruction is selected. In prompting, APE marks the shift from handcrafted wording toward automated prompt optimization, where the model itself discovers phrasing that people might not think to try.
The approach was introduced in 2022 research that framed instruction design as natural-language program synthesis. Its central finding was that model-generated instructions often matched or exceeded prompts written by people across instruction induction and reasoning benchmarks, which made APE a reference point for later techniques in artificial intelligence such as OPRO and gradient-free prompt search.
How the automatic prompt engineer search works
APE runs a propose, score and select loop. The user supplies a small set of demonstrations, for example ten word pairs that show antonyms, and a scoring function. The proposal model then infers what instruction could have produced those outputs, and an evaluation model tests each candidate on separate examples.
- Proposal: an LLM receives demonstrations and generates dozens of candidate instructions, often 50 or more.
- Scoring: each candidate is run on a held-out subset and scored by execution accuracy or by the log probability of the desired outputs.
- Filtering: low-scoring candidates are discarded, and the top fraction is kept.
- Resampling: optionally, the model writes semantic variations of the best candidates, and the cycle repeats.
- Selection: the highest-scoring instruction is returned for production use.
Proposal comes in two styles. Forward generation asks the model to continue a template such as “The instruction was” after the demonstrations. Reverse generation uses a model that can fill a blank in the middle of a text, which places the instruction slot before the examples and often yields more natural phrasing.
Key parameters and design choices
The quality of an APE run depends on a handful of settings that trade cost against coverage. The table below lists the decisions that most affect results.
| Parameter | Typical range | Effect on results |
|---|---|---|
| Number of candidates | 20 to 200 per round | More candidates raise the chance of a strong prompt but cost more calls |
| Demonstrations per proposal | 3 to 10 examples | Too few hide the task; too many crowd the context |
| Scoring set size | 20 to 100 examples | Small sets reward lucky prompts and overfit |
| Scoring function | Execution accuracy or log probability | Must match the real success criterion |
| Search rounds | 1 to 3 iterations | Gains usually shrink after the first resampling round |
Original experiments reported that iterative Monte Carlo search improved prompts only modestly over a single well-sized proposal round. The decisive factor was usually the size and quality of the candidate pool, together with a scoring set that reflects real inputs.
APE compared with other prompt optimization methods
APE is one member of a broader family of automated prompt search methods. They differ in how they generate new prompts and in whether they use feedback about specific errors.
| Method | How new prompts are produced | Feedback used |
|---|---|---|
| APE | LLM infers instructions from demonstrations | Scores on held-out examples |
| OPRO | LLM sees a history of prompts with their scores | Score trajectory across iterations |
| Textual gradient methods | LLM criticizes failures and edits the prompt | Natural-language error analysis |
| Evolutionary prompt search | Mutation and crossover of prompt text | Fitness scores per generation |
| Soft prompt tuning | Gradient descent on continuous embeddings | Training loss; needs model weights |
| Manual prompt engineering | A person writes and revises wording | Human judgment and spot checks |
Unlike soft prompt tuning, APE produces readable hard prompts and requires only black-box access to the model. Unlike error-driven methods, it does not explain why a prompt fails, so it is weaker at repairing specific recurring mistakes.
When to use an automatic prompt engineer
APE pays off when a task is well defined, repeated at scale and measurable. It is less useful for open-ended writing where quality cannot be scored automatically.
| Situation | Recommendation | Reason |
|---|---|---|
| Classification or extraction with labels | Use APE | Accuracy is cheap to measure |
| High-volume production prompt | Use APE, then review by hand | Small accuracy gains multiply across many calls |
| Creative or stylistic writing | Prefer manual iteration | No reliable automatic score exists |
| Very few labeled examples | Collect more data first | Scoring becomes noisy and overfits |
| Model changes often | Rerun APE after each change | Optimized wording transfers imperfectly between models |
A sound workflow keeps a separate test set that the search never sees. The selected instruction is evaluated there once, which gives an honest estimate of how it will behave on new production inputs.
Limitations and common mistakes
The main risk is overfitting the scoring set. When hundreds of candidates are compared on a few dozen examples, the winner may simply be the luckiest phrasing. Optimized prompts can also be brittle across models, because wording that suits one model may confuse another.
- Metric mismatch: optimizing exact-match accuracy can reward terse outputs that fail real users.
- High compute cost: hundreds of candidates times dozens of examples quickly add up to thousands of calls.
- Opaque wording: winning prompts may be odd phrases that teams hesitate to maintain.
- Narrow scope: APE optimizes the instruction only, not examples, output format or system context.
These limits explain why practitioners treat APE output as a strong starting draft rather than a final answer, and why it is often combined with human review and broader context engineering.
Stripped to the essentials
An automatic prompt engineer lets an AI write instructions for another AI. You show it a few examples of the job. It guesses many possible instructions that could explain them. Then each guess is tested on more examples.
The best scorer wins. Think of it as holding auditions. Many candidates read the same lines, and the one with the best results gets the part. People still check the winner before it goes live.
Where it is applied
A customer support team routes about 20,000 incoming emails per day into twelve categories with a language model. Their handwritten instruction reaches roughly 84 percent accuracy on a labeled sample, and misrouted emails slow down replies. An engineer collects 300 labeled emails and splits them into proposal, scoring and test sets.
An APE run generates 80 candidate instructions from small groups of examples, scores each on 100 emails and resamples variations of the top ten. The winning instruction explicitly separates billing disputes from refund requests, a distinction the original prompt blurred. On the untouched test set it reaches about 89 percent accuracy. The team edits the wording slightly for readability, confirms the score holds and deploys it, which noticeably reduces manual rerouting work each day.