Prompt Engineering a Prompt Engineer

Qinyuan Ye, Mohamed Ahmed, Reid Pryzant, Fereshte Khani · Submission to ICLR 2024 · Rejected

TL;DR

This paper introduces PE2, a method that significantly improves automatic prompt engineering by applying "meta-prompting" techniques to the prompt-writing process itself. By providing Large Language Models (LLMs) with structured reasoning templates and detailed task descriptions, PE2 consistently outperforms existing baselines and human-written prompts across diverse tasks, including complex math and real-world production scenarios.

The "Guidance Gap" in Automatic Prompt Engineering

LLMs are notoriously sensitive to how a task is phrased. Finding the "perfect" prompt usually involves hours of manual trial-and-error by human engineers. While recent research has explored Automatic Prompt Engineering (APE)—using one LLM to write prompts for another—these "meta-models" often struggle with the complex reasoning required to diagnose why a prompt is failing and how to fix it.

The authors identify a "guidance gap": current meta-prompts are often too brief. They expect the model to generate "textual gradients" (feedback) and new prompts on the fly without a clear, step-by-step reasoning framework.

Methods: The PE2 Approach

To bridge this gap, the authors propose PE2 (Prompt Engineered Prompt Engineer). PE2 infuses the meta-prompt with three key components designed to elicit better reasoning from the LLM acting as the "engineer":

The PE2 meta-prompt incorporates a two-step task instruction, context specification, and a step-by-step reasoning template to guide the LLM.
  1. Two-step Task Description: Instead of a vague instruction, PE2 explicitly defines a two-step process: first, examine the current prompt and failure examples; second, propose a new prompt based on that reasoning.
  2. Context Specification: It explicitly defines the layout of the prompt and input (e.g., whether the instruction should appear before or after the question), recognizing that the "where" matters as much as the "what."
  3. Step-by-step Reasoning Template: This acts as a "Chain-of-Thought" for the prompt engineer. The model is guided by a list of questions: Is the output correct? Is the prompt describing the task correctly? Is an edit necessary? This forces the model to hypothesize about errors before jumping to a solution.

The system uses a search procedure that selects the top-performing prompts at each step and proposes new variants for each, effectively "evolving" the prompt over several iterations.

Key Insights and Ideas

  • Meta-prompts need prompt engineering too: Just as "Let's think step by step" helps a model solve math, giving the "engineer" model a structured reasoning template helps it write better prompts.
  • Targeted Edits vs. Paraphrasing: Earlier APE methods often just paraphrased prompts. PE2 performs "targeted edits"—it might realize a model is failing at subtraction and explicitly add an instruction to "remember to subtract as needed."
  • The "Shortcut Learning" Risk: In counterfactual tasks (like base-8 math), the model sometimes invented its own "fake" arithmetic rules that happened to work for the small training batch but weren't mathematically sound. This highlights a potential pitfall in automated optimization: models might find "hacks" rather than generalizable instructions.
  • Model Specificity: Prompts optimized for one model (like GPT-4) don't always transfer perfectly to others (like Mistral). Prompt engineering appears to be a model-specific optimization task.

Key Results Across Diverse Datasets

The authors evaluated PE2 across five diverse groups of tasks, including math reasoning (MultiArith, GSM8K), Instruction Induction, BIG-bench Hard, Counterfactual Evaluation, and a massive real-world internal Microsoft classification prompt (>5,000 tokens).

PE2 consistently outperforms baseline initialization and prior automatic prompt engineering methods across diverse benchmarks and a real-world production prompt.
  • Math: PE2 outperformed the famous "Let's think step by step" prompt by 6.3% on MultiArith and 3.1% on GSM8K.
  • Counterfactuals: It beat baseline initializations on counterfactual tasks by an average of 10.6%, showing strong reasoning capabilities over standard APE methods.
  • Real-world Impact: When applied to the expert-written production prompt, PE2 achieved an 8.0% increase in F1 score, proving it can handle industrial-scale complexity.
  • Stability: Ablation studies showed that removing the reasoning template or task descriptions led to much higher variance and more frequent "low-quality" prompt suggestions.

Limitations and Future Work

  • Cost and Budget: The iterative search process is computationally expensive. The authors limited their experiments to 3 optimization steps with a small number of candidates per step.
  • Proprietary Model Dependence: The study primarily used GPT-4 and text-davinci-003. While the concepts are model-agnostic, the results might vary with smaller, open-source models.
  • Future Direction: The authors are excited about "self-referential" optimization—using PE2 to optimize the PE2 meta-prompt itself, potentially creating a recursive loop of prompt improvement.

Summary updated

BibTeX
@misc{ye2023prompt,
  author = {Qinyuan Ye and Mohamed Ahmed and Reid Pryzant and Fereshte Khani},
  title = {{Prompt Engineering a Prompt Engineer}},
  year = {2023},
  eprint = {2311.05661},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2311.05661},
}
Figure