P rompt W izard: Optimizing Prompts via Task-Aware, Feedback-Driven Self-Evolution (2025)

Abstract: Large language models (LLMs) have transformed AI across diverse domains, with prompting being central to their success in guiding model outputs. However, manual prompt engineering is both labor-intensive and domain-specific, necessitating the need for automated solutions. We introduce PromptWizard, a novel, fully automated framework for discrete prompt optimization, utilizing a self-evolving, self-adapting mechanism. Through a feedback-driven critique and synthesis process, PromptWizard achieves an effective balance between exploration and exploitation, iteratively refining both prompt instructions and in-context examples to generate human-readable, task-specific prompts. This guided approach systematically improves prompt quality, resulting in superior performance across 45 tasks. PromptWizard excels even with limited training data, smaller LLMs, and various LLM architectures. Additionally, our cost analysis reveals a substantial reduction in API calls, token usage, and overall cost, demonstrating PromptWizard’s efficiency, scalability, and advantages over existing prompt optimization strategies.

## introduction large language models (llms) like @xcite have achieved remarkable performance across diverse tasks @xcite @xcite . at the core of this success is prompting-the process of providing input instructions to guide models toward desired outputs. studies have shown that prompting significantly influences llm performance, making prompt engineering-the design and refinement of prompts-critical for maximizing accuracy @xcite . however, crafting effective prompts remains a labor-intensive and domain-specific task, requiring human expertise and subjective judgment. as models evolve and tasks vary, the need to repeatedly design prompts raises an important question: can prompt engineering be automated to streamline this process and enhance scalability? automatically generating optimal prompts is a key challenge in the era of llms @xcite . some approaches, such as gradient-based methods, have been used to optimize prompts by leveraging token probabilities and model gradients @xcite . however, these methods are limited to white-box (open-source) models, as they require direct access to the model's internal mechanics @xcite . the most powerful llms today, like gpt-4 and gemini, are typically black-box (closedsource) and accessible only through apis, making such techniques impractical. this necessitates gradient-free prompt optimization strategies. existing methods primarily focus on enumerating diverse prompts or refining existing ones @xcite @xcite @xcite , broadly categorized into continuous, discrete and feedback-based approaches. continuous methods, such as instructzero @xcite and instinct @xcite , model prompt optimization as a continuous problem using soft prompts. these are processed by open-source llms to generate candidate instructions, which are then evaluated by the target black-box llm. the feedback trains a bayesian optimizer (bo) or neural network (nn) to predict improved instructions. however, these approaches require additional nn training and their effectiveness depends on the open-source model and task complexity. learning an optimal prompt-performance mapping becomes challenging for complex tasks. in contrast, discrete methods, such as prompt-breeder @xcite and evo-prompt @xcite , generate multiple prompt variations using evolutionary or selfreferential strategies. while these expand the search space, they lack direct feedback mechanisms, resulting in inefficient and suboptimal exploration. feedback-based approaches, including apo @xcite and promptagent @xcite , leverage llm-generated feedback by analyzing incorrect responses to refine prompts. however, these methods are computationally expensive, requiring hours to converge on optimal prompts. similarly, dspy @xcite employs a modular approach by integrating techniques like cot and react, but suffers from high computational costs and complexity. in this paper, we propose promptwizard (pw), a discrete prompt optimization framework for blackbox llms. promptwizard employs a self-evolving mechanism where the llm generates, critiques, and refines its own prompts and examples, continuously improving through iterative feedback and synthesis. this self-adaptive approach ensures holistic optimization by evolving both the instructions and in-context examples for better task performance. promptwizard operates in two phases: (i) prompt generation (one-time), where it processes a high-level problem description and training samples, using llms to mutate, score, critique, synthesize, reason, and validate prompts and examples; (ii) inference (test-time), where the final optimized prompt and examples are applied to test samples. pw follows a structured strategy (see figure 1 ): starting with a problem description and an initial prompt, pw generates instruction variations by prompting llms to mutate them. the bestperforming prompt is selected, with a built-in critique component guiding refinement-unlike the uncontrolled evolution in prior methods @xcite . à unlike other discrete approaches, pw also optimizes in-context examples. it selects diverse examples from training data, identifying positive and negative cases based on performance, where negative examples inform further refinements. ã instructions and exam-ples are sequentially optimized, leveraging critiquedriven synthetic examples to address prompt weaknesses. these examples are integrated to refine the prompt further. õ pw enhances problem-solving by generating detailed reasoning chains via chainof-thought (cot). oe to improve performance and interpretability, pw aligns prompts with human reasoning by incorporating task intent and expert personas. our work distinguishes itself from prior approaches in several key aspects: 1. guided exploration: promptwizard introduces a feedbackdriven critique-and-synthesis mechanism, systematically refining prompts based on performance insights. this guided exploration mitigates the randomness and inefficiencies of methods like prompt-breeder @xcite , opro @xcite , and evoprompt @xcite (section 3.1). 2. sequential optimization of instructions and examples: unlike methods that optimize instructions and examples separately, promptwizard optimizes both dynamically and iteratively. this joint exploitation of task-specific nuances leads to superior prompt quality (section 3.3). ## related work prompt optimization research has increasingly focused on automating prompt creation to overcome the limitations of handcrafted prompts @xcite @xcite . recent approaches fall into: continuous, discrete and feedback-based optimization @xcite . we review these methods, their limitations, and how promptwizard (pw) advances the field. ## promptwizard framework we introduce promptwizard (pw), a generalpurpose framework designed to optimize prompts through a self-evolving and self-adapting mechanism (see figure 1 ). pw harnesses the capabilities of llms to iteratively synthesize, critique, and refine both prompt instructions and in-context examples, tailoring them to specific tasks across diverse domains. the five key steps are described next and algorithm 1 provides pseudo code for entire promptwizard framework. problem formulation. in our approach, we start with an initial prompt instruction p e.g., "let's think step by step to arrive at the solution of this mathematical problem"), along with a problem description and a set of training samples represented as (q, a) = {(q i , a i )} n @xmath0, where q i and a i are input-output pairs (questions and answers). the llm model l generates outputs with probabilities p l (a i | q i , p, a f , q f ), where q f and a f are the few-shot examples. the goal of promptwizard is to iteratively optimize both the prompt and the few-shot examples to maximize task accuracy a, which represents the model's performance on the target task. the refined prompt p should improve the model's ability to generate accurate outputs. ## experiments & implementation details tasks & datasets. we assess the effectiveness of promptwizard on the widely-used big-bench instruction induction (bbii) dataset, a benchmark for prompt optimization in recent works such as instinct @xcite , instructzero @xcite , and ape @xcite . the dataset covers a diverse range of language understanding scenarios (appendix a). we also evaluate promptwizard on three arithmetic reasoning datasets: gsm8k @xcite , aquarat @xcite , and svamp @xcite , as well as domain-specific tasks from bigbench hard (bbh) @xcite , which includes 23 challenging tasks. this brings the total to 45 tasks (19 bbii, 23 bbh, 3 math tasks), covering both general and domain-specific problem settings. additional details of all datasets are in appendix b. baselines. we compare our promptwizard with five representative sota discrete and continuous methods: instinct @xcite , in-structzero @xcite , promptbreeder (pb) @xcite , evoprompt @xcite , and ape @xcite . implementation details. we experiment with both gpt3.5turbo and gpt-4 as the black-box llms for prompt optimization in promptwizard. all the individual components such as mutate, ## ethical considerations promptwizard optimizes prompts without direct model fine-tuning, reducing risks of unintended biases amplification. however, since it relies on black-box llms, biases inherent in these models may persist. to mitigate this, we ensure diversity in prompt mutations and conduct fairness evaluations. additionally, pw prioritizes efficiency, minimizing excessive computational costs and environmental impact. responsible deployment requires continuous monitoring to prevent unintended ethical risks in downstream applications.