Prompt Engineering a Prompt Engineer

Qinyuan Ye, Maxamed Axmed, Reid Pryzant, Fereshte Khani

TL;DR

PE2 (Prompt Engineered Prompt Engineer) introduces a systematic way to automate prompt engineering by optimizing the meta-prompts used to guide LLMs. By infusing structured reasoning templates, detailed task descriptions, and context specifications into the meta-prompt, PE2 significantly outperforms existing automatic prompt generation baselines across math reasoning, counterfactual tasks, and large-scale production prompts.

What Problem Does This Paper Address?

Large Language Models (LLMs) are notoriously sensitive to prompt design, often requiring extensive manual trial-and-error—known as prompt engineering—to achieve peak performance. While recent research has attempted to automate this process by using an LLM to evaluate errors and propose new prompts (a process called meta-prompting), these automated "prompt engineers" are often limited.

The authors argue that prompt engineering is fundamentally a complex reasoning task that involves diagnosing errors, forming hypotheses, and clearly communicating instructions. Existing automatic methods provide insufficient guidance within their meta-prompts, failing to trigger the deep reasoning capabilities of the LLM acting as the optimizer.

Methods

To bridge this gap, the authors propose PE2, which applies prompt engineering principles directly to the meta-prompt itself.

Figure 3: An redacted example to illustrate the meta-prompt components introduced in §3.

PE2 enhances the meta-prompt using three core components:

  1. Two-step Task Description: Explicitly instructs the LLM upfront to first analyze the prompt and failure examples (Step 1), and then propose an improved prompt based on that analysis (Step 2).
  2. Context Specification: Clearly defines the layout and formatting of how the prompt and input text are concatenated, ensuring the LLM understands the exact execution context.
  3. Step-by-step Reasoning Template: Provides a structured list of diagnostic questions for the LLM to answer for each failure example (e.g., "Is the prompt correctly describing the task?", "Is it necessary to edit the prompt?").

These components are integrated into an iterative search procedure where the LLM samples batches of model errors, generates textual feedback ("gradients"), and proposes updated prompt candidates.

Datasets

The authors evaluated PE2 across a diverse suite of benchmarks:

  • Math Reasoning: MultiArith and GSM8K.
  • Instruction Induction: 14 diverse language tasks designed to infer underlying instructions from few-shot examples.
  • BIG-bench Hard (BBH): 27 challenging subtasks, including movie recommendation and temporal sequences.
  • Counterfactual Evaluation: 12 subtasks spanning arithmetic (e.g., base-8 addition), chess legality, and syntax variations, testing the model's ability to reason through non-standard rules.
  • Production Prompt: A real-world, internal hierarchical multi-label classification prompt containing over 5,000 tokens.

Key Insights and Ideas

  • Meta-Prompts Need Chain-of-Thought Too: Just as standard LLMs benefit from "thinking step-by-step" on hard tasks, LLM-based prompt optimizers require structured reasoning templates to effectively diagnose prompt failures.
  • The Danger of "Shortcut Learning": In counterfactual tasks like base-8 addition, when PE2 was not explicitly told the base changed, it successfully invented its own partially correct arithmetic heuristics from examples (e.g., "if both numbers are less than 50, add 2 to the sum"). While clever, this mimics the "shortcut learning" failure modes often seen in gradient-based neural network optimization.
  • Lack of Cross-Model Generalization: Prompts optimized by PE2 for a specific task model (like text-davinci-003) did not consistently transfer effectively to other models (like mistral-7b). This suggests that automated prompt engineering yields highly model-specific instructions tailored to a model's unique quirks.

Key Results

PE2 consistently matched or outperformed competitive baselines like Iterative APE and APO.

Figure 2: Results Overview. Our method PE2 consistently brings improvements over the prompt initialization (marked with orange text). It matches or outperforms prompt optimization baselines Iterative APE (Zhou et al., 2023b) and APO (Pryzant et al., 2023) across a wide range of language tasks, with most significant performance gain observed on Conterfactual Eval (Wu et al., 2024). See detailed performance breakdown in Fig. 10-13.
  • Math Benchmarks: PE2 discovered prompts that outperformed the standard "let's think step by step" baseline by 6.3% on MultiArith and 3.1% on GSM8K.
  • Counterfactual Tasks: PE2 achieved a 15.9% average accuracy boost over prompt initialization on counterfactual evaluations, demonstrating a unique capability to adapt to non-standard scenarios.
  • Production Scaling: When applied to a massive, expert-written production prompt (>5,000 tokens), PE2 successfully engineered targeted edits that resulted in an 8.0% absolute increase in F1 score.

Additionally, analysis of the optimization dynamics showed that PE2 maintains a superior balance between exploration and stability compared to alternative methods.

Figure 4: Prompt optimization dynamics of Iterative APE, APO and PE2 on MultiArith. The violins repre- sent the quality distributions of newly proposed prompts at each optimization step. PE2 has a better balance be- tween exploration and stability.

Limitations and Future Work

A primary limitation of the study is the small prompt search budget ($T=3$ steps) enforced due to API cost constraints. Furthermore, the evaluation relied heavily on proprietary models (gpt-4, text-davinci-003), raising long-term reproducibility concerns as these models evolve or face deprecation. The tasks were also predominantly restricted to the English language.

For future work, the authors highlight the need to mitigate LLM hallucinations during prompt generation (e.g., when the optimizer falsely claims the ground-truth labels are wrong) and express excitement about exploring self-referential optimization—using PE2 to optimize its own meta-prompt.

Summary updated

BibTeX
@misc{ye2023prompt,
  author = {Qinyuan Ye and Maxamed Axmed 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