Source-linked AI summary

Large Language Models Are Human-Level Prompt Engineers

Yongchao Zhou, Andrei Ioan Muresanu, Ziwen Han, Keiran Paster, Silviu Pitis, Harris Chan, Jimmy Ba

arXiv:2211.01910v2cs.LGcs.AIcs.CL

TL;DR

LLM behavior depends on prompt quality, yet effective natural-language instructions often require costly human experimentation. APE treats instructions as programs, using LLMs to propose and search over candidates scored on the target model. Across 24 NLP tasks, it achieves human-level or better performance on most evaluated tasks and supports applications including few-shot learning and behavioral steering.

  • Problem

    Plain-language prompts can fail despite successful alternative instructions, while users have limited knowledge of instruction–model compatibility and must experiment extensively.

  • Method

    APE formulates instruction generation as black-box natural-language program synthesis, generating candidates from demonstrations, scoring them, and searching for better instructions.

  • Results

    APE achieves equal or better than human performance on 24 of 24 Instruction Induction tasks and outperforms the Greedy baseline on every task.

  • Takeaways & Limitations

    APE-generated prompts can support few-shot learning, zero-shot chain-of-thought prompting, and steering models toward truthfulness or informativeness.

  • Takeaways & Limitations

    The proposal process may fail when the initial candidate set lacks diversity or contains no suitably high-scoring instruction.

Abstract

from arXiv · show

By conditioning on natural language instructions, large language models (LLMs) have displayed impressive capabilities as general-purpose computers. However, task performance depends significantly on the quality of the prompt used to steer the model, and most effective prompts have been handcrafted by humans. Inspired by classical program synthesis and the human approach to prompt engineering, we propose Automatic Prompt Engineer (APE) for automatic instruction generation and selection. In our method, we treat the instruction as the "program," optimized by searching over a pool of instruction candidates proposed by an LLM in order to maximize a chosen score function. To evaluate the quality of the selected instruction, we evaluate the zero-shot performance of another LLM following the selected instruction. Experiments on 24 NLP tasks show that our automatically generated instructions outperform the prior LLM baseline by a large margin and achieve better or comparable performance to the instructions generated by human annotators on 19/24 tasks. We conduct extensive qualitative and quantitative analyses to explore the performance of APE. We show that APE-engineered prompts can be applied to steer models toward truthfulness and/or informativeness, as well as to improve few-shot learning performance by simply prepending them to standard in-context learning prompts. Please check out our webpage at https://sites.google.com/view/automatic-prompt-engineer.

1 INTRODUCTION

LLMs offer broad capabilities but natural-language prompts can be unreliable and require costly human experimentation. APE frames instruction generation as black-box natural-language program synthesis, automatically searching and selecting instructions, and achieves human-level zero-shot performance across evaluated tasks.

  • LLMs provide general capabilities across diverse zero-shot and few-shot tasks, but controlling their behavior remains an open question.
  • Plain-language prompts may fail even when alternative instructions succeed, forcing users to experiment because instruction–model compatibility is difficult to predict.
  • APE treats instruction generation as natural-language program synthesis and black-box optimization guided by LLM-generated candidates and downstream scores.
  • APE generates candidate instructions from input-output demonstrations, scores them under the target model, and uses naive or iterative Monte Carlo search to refine the search.
  • 24/24 Instruction Induction and 17/21 Big-Bench tasks reach human-level performance with model-generated instructions.
  • APE analyses also demonstrate applications to few-shot learning, zero-shot chain-of-thought prompting, truthfulness, and informativeness.

2 RELATED WORK

Related work establishes LLMs as general-purpose systems with capabilities including in-context learning, reasoning, instruction following, and instruction induction. APE connects prompt engineering with program synthesis by searching natural-language instruction programs generated from demonstrations.

  • Scaling language models has produced capabilities including few-shot in-context learning, zero-shot problem solving, chain-of-thought reasoning, instruction following, and instruction induction.
  • Prompting is a flexible interface for generalist models, but models may interpret prompts differently from humans, motivating manual and automatic prompt engineering.
  • Program synthesis searches a program space for programs satisfying specifications such as input-output examples or natural language.
  • APE differs from classical program synthesis by leveraging LLM structure to search natural-language programs and using inference models to generate candidates from demonstrations.

3 NATURAL LANGUAGE PROGRAM SYNTHESIS USING LLMS

APE frames natural language instruction design as black-box program synthesis: an LLM proposes candidate instructions, which are scored and filtered to select a high-performing prompt. The method supports multiple proposal modes, score functions, efficient evaluation, and optional iterative resampling when initial candidates are inadequate.

  • 3 NATURAL LANGUAGE PROGRAM SYNTHESIS USING LLMS: APE treats instruction generation as black-box optimization over LLM-proposed candidate programs, selecting an instruction that maximizes a score on training examples.The candidate pool can be generated from input/output demonstrations and searched for high-scoring instructions.
  • 3 NATURAL LANGUAGE PROGRAM SYNTHESIS USING LLMS: APE begins with LLM-sampled instruction proposals, evaluates them on training subsets, retains high-scoring candidates, and returns the highest-scoring instruction.The procedure can either keep the top candidates or resample them with an LLM until convergence.
  • Proposal generation: Forward generation predicts instructions from demonstrations, while reverse generation allows instructions to appear flexibly within the surrounding text.Customized prompts can seed reverse generation for tasks such as TruthfulQA.
  • Score functions: APE evaluates candidate instructions with execution accuracy or log probability, trading a discrete correctness signal against a finer-grained probabilistic signal.Execution accuracy is generally a 0-1 match between the model output and target answer, while log probability scores the desired answer directly.
  • Iterative proposal distributions: Iterative APE resamples instructions near high-scoring candidates when the initial proposal set lacks diversity or suitably high-scoring options.Although iterative generation improves proposal-set quality, the highest-scoring instruction usually remains unchanged, so non-iterative APE is the default.

4 LARGE LANGUAGE MODELS ARE HUMAN-LEVEL PROMPT ENGINEERS

APE automatically generates and selects natural-language instructions, achieving human-level or better performance across instruction-induction tasks and extending to few-shot learning, chain-of-thought reasoning, and truthfulness-related objectives.

  • 4 LARGE LANGUAGE MODELS ARE HUMAN-LEVEL PROMPT ENGINEERS: APE uses LLMs to generate and select instructions for steering models across zero-shot and few-shot tasks.The method frames instruction generation as natural language program synthesis and evaluates selected instructions through downstream execution.
  • 4.1 INSTRUCTION INDUCTION: 24/24 tasks achieved performance equal to or better than human prompt engineers, with APE outperforming the Greedy baseline on every task.Across the 24 tasks, APE obtained an IQM of 0.810 versus 0.749 for human-engineered prompts.
  • 4.1 INSTRUCTION INDUCTION: APE-generated instructions produced comparable or better few-shot test performance than standard in-context learning on 21 of 24 tasks.The selected instructions were prepended to in-context demonstrations; performance decreased on Rhymes, Large Animal, and Second Letters under zero-shot-based selection.
  • 4.2 BIGBENCH: APE achieved comparable or better performance than default human prompts on 17 of 21 BIG-Bench Instruction Induction tasks.The evaluation used reverse-mode candidate generation, execution-accuracy ranking, and zero-shot testing on the selected instruction.
  • 4.4 TRUTHFULQA: TruthfulQA results were not compatible with the original zero-shot benchmark because instructions were optimized using 100 question-answer pairs as training demonstrations.The authors therefore characterize the setup as not true few-shot learning.
  • 4.4 TRUTHFULQA: On TruthfulQA, APE outperformed the human-engineered prompt using 200 InstructGPT-generated candidates.The comparison evaluated truthfulness, informativeness, and their combination on training and test examples.
  • 4.4 TRUTHFULQA: APE achieved over 40% accuracy for answers that were both true and informative, versus 30% for the human “help” prompt.The discovered instructions tended toward the two ends of the truthfulness-informativeness Pareto frontier.

5 QUANTITATIVE ANALYSIS

The quantitative analyses examine proposal quality, scoring, candidate counts, and iterative search, showing that larger models and execution-accuracy-based selection generally improve instruction discovery while iterative gains diminish.

  • 5 QUANTITATIVE ANALYSIS: Larger and more powerful language models were more cost-effective for generating the best prompt despite higher per-token costs.The analysis examined proposal distributions, score functions, iterative search, and cost efficiency.
  • 5.2 LLMS FOR SELECTION: Increasing instruction candidates from 4 to 128 produced monotonically increasing best-instruction accuracy with diminishing returns, reaching human-level performance at 64 samples.The authors selected 50 as the default sample size.
  • 5.2 LLMS FOR SELECTION: Small models still yielded promising instructions after selection, enabling APE to outperform the Greedy approach across all eight evaluated models.The proposal-quality analysis generated 250 instructions per model and assessed execution accuracy.
  • 5.2 LLMS FOR SELECTION: Execution accuracy aligned better with test performance than the alternative metric across 24 instruction-induction tasks, so it became the default score.The comparison used Spearman correlations from 250 instructions per task evaluated on 10 test points.
  • 5.2 LLMS FOR SELECTION: Iterative search increased proposal-set quality across rounds but showed diminishing returns, stabilizing after approximately three rounds.The result was observed through survival functions and test-accuracy histograms, including Passivization.
  • 5.2 LLMS FOR SELECTION: Iterative APE marginally improved tasks where standard APE underperformed humans while achieving similar performance on other tasks.This comparison covered six tasks and supports using iterative search when generating a strong initial instruction is difficult.

6 CONCLUSION

APE automates prompt discovery for models with natural-language interfaces and achieves human-level performance across evaluated tasks with minimal human input.

  • APE treats language-model prompts as programs and searches over candidate instructions to steer models toward desired behaviors.
  • The framework extends beyond LLMs when suitable proposal methods and scoring functions can be designed for other natural-language interfaces.

B IMPLEMENTATION DETAILS

The implementation constructs a clean Big-Bench evaluation subset through explicit filtering and manual categorization, then uses standardized prompting templates for evaluation.

  • The study duplicates task descriptions for 24 instruction-induction tasks and defines BBII as a clean subset of 21 tasks with clear human-written instructions.
  • Big-Bench tasks are filtered for JSON format, single-task structure, at least 150 input-output examples, reported human or random performance, and classification or exact-match evaluation.
  • The implementation records filtering criteria and raw model-prompting templates for the experiments.
  • Manual inspection divides remaining tasks into BBII, invalid-format, and other categories, with BBII used for evaluation in Section 4.2.
  • Tasks outside scope because they require specialized knowledge or cannot be solved within 60 minutes are discarded.
  • The evaluation templates include “Answer the following question.” and a question-answer format containing an insertion point for the generated instruction.

C.1 INSTRUCTION INDUCTION

APE-generated instructions improve few-shot in-context performance on most instruction-induction tasks, while performance can depend on the selection metric and instruction-context compatibility.

  • C.1 INSTRUCTION INDUCTION: APE improves or matches few-shot test performance on 21 of 24 instruction-induction tasks when its instruction is prepended to in-context demonstrations.
  • C.1 INSTRUCTION INDUCTION: Adding in-context examples hurts performance for Rhymes, Large Animal, and Second Letters under instructions selected by zero-shot execution accuracy.
  • C.1 INSTRUCTION INDUCTION: The authors conjecture that zero-shot-selected instructions may overfit zero-shot learning and transfer poorly to few-shot settings.
  • C.1 INSTRUCTION INDUCTION: Few-shot execution accuracy performs comparably or slightly better than zero-shot selection except on Rhymes.
  • C.1 INSTRUCTION INDUCTION: On Rhymes, 4 of 5 filtered instructions ask the model to echo the input word, producing near-perfect test accuracy by exploiting self-rhyming.
  • C.1 INSTRUCTION INDUCTION: Combining those echoing instructions with demonstrations creates a mismatch between trivial instruction-induced rhymes and non-trivial context-induced rhymes.
  • C.2 BIG-BENCH INSTRUCTION INDUCTION: APE improves or matches normalized zero-shot performance on 17 out of 21 BIG-Bench Instruction Induction tasks.

C.3 ZERO-SHOT CHAIN OF THOUGHT REASONING

APE discovers a general zero-shot chain-of-thought instruction that improves performance over the standard prompt on selected reasoning benchmarks and across several evaluated tasks.

  • APE discovers the prompt “Let’s work this out in a step by step way to be sure we have the right answer.” as an alternative to “Let’s think step by step.”
  • 3.3 points: MultiArith performance rises from 78.7 to 82.0 with text-davinci-002 using the APE prompt.
  • 2.3 points: GSM8K performance rises from 40.7 to 43.0 with text-davinci-002 using the APE prompt.
  • The APE chain-of-thought prompt improves performance on 6/12 tasks and nearly matches human performance on 4/12 tasks.
  • Shuffled Objects and Last Letter are hypothesized to be difficult to optimize with a general prompt.
  • The comparison uses zero-shot chain-of-thought performance on MultiArith, with the original prompt attributed to Kojima et al. and alternative templates reported in the evaluation table.

C.4 QUANTITATIVE ANALYSIS

APE’s performance depends on the relationship between proposal, scoring, and execution models, while meta-prompt templates alter which instructions are proposed. Transfer across models can be substantially weaker than within-model use.

  • InstructGPT achieved the best instruction-generation performance among the compared models on six selected tasks.The evaluation covered zero-shot and few-shot settings.
  • Meta-prompt templates changed the distribution of proposed instructions, improving some tasks while impairing others.A TruthfulQA-derived template enabled stronger membership accuracy than the original template on some comparisons.
  • Instruction transfer caused a significant performance drop when InstructGPT instructions steered GPT-3 or GPT-3 instructions steered InstructGPT.The drop was mitigated by a human-written instruction, and model-generated instructions performed best when matched to their originating model.
  • The six-task evaluation included spelling, morphosyntax, lexical semantics, semantics, multilingual, and GLUE categories.Two tasks were below human performance and four were human-level.

D COST ANALYSIS

APE’s cost and prompt-length analyses show that larger aligned models can be cost-efficient because they generate concise instructions, while APE prompts reduce inference-time token use compared with demonstrations.

  • Cost analysis: Larger, human-aligned models dominate APE’s accuracy-cost frontier despite higher per-token prices.Their more concise generated instructions reduce scoring costs.
  • Prompt efficiency: APE instructions reduce prompt tokens by up to an order of magnitude compared with in-context learning.The offline sampling and scoring expense is treated as a one-time overhead amortized over many inferences.
  • Prompt efficiency: More capable models produce more concise instructions, whereas models without human-instruction training tend to reach the maximum allowed output length.Figure 12 compares instruction length and accuracy across eight OpenAI models and 24 tasks.
  • Evaluation scope: APE-selected instructions were evaluated across zero-shot and few-shot settings, multiple models, proposal templates, metrics, and transfer conditions.The supplied analyses cover 24-task and six-task evaluations, including iterative search and in-context-learning comparisons.
Loading 2211.01910v2…