GEPA: Reflective Prompt Evolution Can Outperform Reinforcement Learning — part 1/4
Cleaned-text code points [0, 15394). Bibliography omitted here; source.md includes it.
# GEPA: Reflective Prompt Evolution Can Outperform Reinforcement Learning
###### Abstract
Large language models (LLMs) are increasingly adapted to downstream tasks via reinforcement learning (RL) methods like Group Relative Policy Optimization (GRPO), which often require thousands of rollouts to learn new tasks. We argue that the interpretable nature of language often provides a much richer learning medium for LLMs, compared to policy gradients derived from sparse, scalar rewards. To test this, we introduce GEPA ( Ge netic- Pa reto), a prompt optimizer that thoroughly incorporates natural language reflection to learn high-level rules from trial and error. Given any AI system containing one or more LLM prompts, GEPA samples trajectories (e.g., reasoning, tool calls, and tool outputs) and reflects on them in natural language to diagnose problems, propose and test prompt updates, and combine complementary lessons from the Pareto frontier of its own attempts. As a result of GEPA’s design, it can often turn even just a few rollouts into a large quality gain. Across six tasks, GEPA outperforms GRPO by 6% on average and by up to 20%, while using up to 35x fewer rollouts. GEPA also outperforms the leading prompt optimizer, MIPROv2, by over 10% (e.g., +12% accuracy on AIME-2025), and demonstrates promising results as an inference-time search strategy for code optimization. We release our code at https://github.com/gepa-ai/gepa .
## 1 Introduction
Large language models (LLMs) have enabled development of agents and systems that combine fuzzy natural-language specifications with tools like retrieval and code execution. This raises the question of how LLMs should be optimized for downstream performance. One popular approach is Reinforcement Learning with Verifiable Rewards (RLVR), e.g. with Group Relative Policy Optimization (GRPO) ( Shao et al., 2024 ) , which treats success metrics as end-of-rollout scalar rewards used to estimate policy gradients ( Lambert, 2025 ) . While these RL approaches are effective, they typically require tens of thousands of rollouts in practice to fit new tasks. For example, recent works leveraging GRPO typically use up to hundreds of thousands of rollouts for training ( Chen et al., 2025c ; Wu et al., 2025b ; Zhang et al., 2025 ; Jin et al., 2025 ; Si et al., 2025 ; Wang et al., 2025a ; Chen et al., 2025a ; Sha et al., 2025 ; Lin et al., 2025a ; Peng et al., 2025 ; Song et al., 2025 ) . This sample inefficiency can quickly become a serious bottleneck: many downstream LLM applications invoke expensive tool calls, have limited inference budget for sampling from the LLM itself, or simply cannot finetune the weights of the largest or best-performing LLMs.
We observe that rollouts sampled from even highly sophisticated LLM systems can be serialized into traces of natural language: they contain nothing but the instructions of each LLM module, the resulting LLM reasoning chains, tool calls, and potentially the internal workings of the reward function (e.g., compiler error messages, before they are collapsed into scalar rewards). Because such serialized trajectories are readily understood by modern LLMs, we argue that algorithms that learn deliberately in natural language by reflecting on these trajectories can make more effective use of the strong language priors that LLMs have, compared with standard RL approaches.
We introduce GEPA (Genetic-Pareto), a reflective prompt optimizer for compound AI systems that merges textual reflection with multi-objective evolutionary search. GEPA iteratively mutates prompts using natural language feedback drawn from new rollouts. In each mutation, the candidate prompt is derived from an ancestor, accumulating high-level lessons derived from observations and LLM feedback. To avoid local optima that afflict greedy prompt optimization, GEPA maintains a Pareto front: instead of evolving only the global best prompt, it stochastically explores the top-performing prompts for each problem instance. This diversification enables robust generalization and mitigates getting stuck in local minima.
We evaluate GEPA across multi-hop reasoning (HotpotQA; Yang et al. 2018 ), Math (AIME, LiveBench-Math; Balunović et al. (2025) ; White et al. (2025) ), instruction following (IFBench; Pyatkin et al. 2025a ), privacy-aware delegation (PUPA; Li et al. 2025a ), and retrieval-augmented verification (HoVer; Jiang et al. 2020 ), using both open (Qwen3 8B; Yang et al. 2025 ; Team 2025 ) and proprietary (GPT-4.1 Mini; OpenAI 2025 ) models. We find that GEPA generalizes well and is highly sample-efficient: on Qwen3 8B, it outperforms GRPO (24k rollouts) by up to 20% while using up to 35 × \times fewer rollouts, with an average gain of +6% across six tasks. GEPA also surpasses the prior state-of-the-art, MIPROv2 ( Opsahl-Ong et al., 2024 ) , on all benchmarks and models, achieving +13% aggregate gains, over double MIPROv2’s +5.6%.
Qualitatively, GEPA-learned prompts are quite rich. Figure 2 shows excerpts from a prompt crafted for the query-creation module of a multi-hop question answering system used in HotpotQA, and Figure 5 shows that even a single reflective update often yields large gains. These results highlight that reflective prompt evolution with language feedback enables improved sample efficiency and robust generalization, offering a practical approach to optimizing complex AI workflows in data- or budget-constrained environments. We also demonstrate GEPA as an inference-time search strategy for code optimization on NPUEval ( Kalade and Schelle, 2025 ) & KernelBench ( Ouyang et al., 2025 ) in Sec 5.1 , and for adversarial prompt search in Sec 5.2 .
## 2 Problem Statement
We follow related work in defining a compound AI system as any modular system composed of one or more language model (LLM) invocations, potentially interleaved with external tool calls, orchestrated through arbitrary control flow. This definition subsumes a broad class of real-world LLM-based AI systems, including agents , multi-agent systems , and general-purpose scaffolding techniques like ReAct ( Yao et al., 2023 ) , Archon ( Saad-Falcon et al., 2025 ) , etc. Following Soylu et al. (2024) ; Khattab et al. (2024) ; Opsahl-Ong et al. (2024) ; Tan et al. (2025) , we formalize such a system as Φ = ( M , C , 𝒳 , 𝒴 ) \Phi=(M,C,\mathcal{X},\mathcal{Y}) , where M = ⟨ M 1 , … , M | M | ⟩ M=\langle M_{1},\ldots,M_{|M|}\rangle denotes language modules, C C specifies control flow logic, and 𝒳 \mathcal{X} , 𝒴 \mathcal{Y} are global input/output schemas. Each module M i = ( π i , θ i , 𝒳 i , 𝒴 i ) M_{i}=(\pi_{i},\theta_{i},\mathcal{X}_{i},\mathcal{Y}_{i}) is an LLM subcomponent: π i \pi_{i} is its (system) prompt including instructions and few-shot demonstrations; θ i \theta_{i} the underlying model weights; 𝒳 i , 𝒴 i \mathcal{X}_{i},\mathcal{Y}_{i} are input/output schemas. At runtime, C C orchestrates the sequencing and invocation of modules—e.g., passing outputs from one module to another, invoking modules conditionally, or leveraging tool APIs. This way, C C can invoke different modules in any order multiples of times.
Given Φ \Phi , let Π Φ = ⟨ π 1 , … , π | M | ⟩ \Pi_{\Phi}=\langle\pi_{1},\ldots,\pi_{|M|}\rangle denote the collection of all module prompts and Θ Φ = ⟨ θ 1 , … , θ | M | ⟩ \Theta_{\Phi}=\langle\theta_{1},\ldots,\theta_{|M|}\rangle the set of module weights. The learnable parameters are thus ⟨ Π , Θ ⟩ Φ \langle\Pi,\Theta\rangle_{\Phi} . For a task instance ( x , m ) (x,m) —where x x maps to the input schema 𝒳 \mathcal{X} and m m contains evaluator metadata (e.g., gold answers, evaluation rubrics, code unit tests)—the system induces an output y = Φ ( x , ⟨ Π , Θ ⟩ Φ ) y=\Phi(x;\langle\Pi,\Theta\rangle_{\Phi}) . A metric μ : 𝒴 × ℳ → [ 0 , 1 ] \mu:\mathcal{Y}\times\mathcal{M}\to[0,1] then measures the output quality of y y with respect to metadata m m (for example by calculating, exact match, F1, pass rate, etc.). The optimization problem is thus defined as follows, where 𝒯 \mathcal{T} is a task distribution.: ⟨ Π ∗ , Θ ∗ ⟩ Φ = arg max ⟨ Π , Θ ⟩ Φ 𝔼 ( x , m ) ∼ 𝒯 [ μ ( Φ ( x , ⟨ Π , Θ ⟩ Φ ) , m ) ] . \displaystyle\langle\Pi^{*},\Theta^{*}\rangle_{\Phi}=\arg\max_{\langle\Pi,\Theta\rangle_{\Phi}}\mathbb{E}_{(x,m)\sim\mathcal{T}}\left[\mu\big(\Phi(x;\langle\Pi,\Theta\rangle_{\Phi}),\,m\big)\right]. (1)
We adopt this general problem formulation, allowing updates to both prompts and weights of language modules, to enable comparisons between optimization algorithms that operate in different parameter spaces (e.g., GEPA vs. GRPO).
#### Sample-Efficient Optimization.
In many real-world scenarios, rollouts—concretely, invocations of Φ \Phi plus evaluation by μ \mu —are often computationally, monetarily, or timewise expensive. The optimizer is thus limited to at most B B rollouts on a dataset 𝒟 train = { ( x , m ) i } i = 1 N \mathcal{D}_{\text{train}}=\{(x,m)_{i}\}_{i=1}^{N} with full access to μ \mu . The goal is to identify parameters ⟨ Π ∗ , Θ ∗ ⟩ Φ \langle\Pi^{*},\Theta^{*}\rangle_{\Phi} that maximize held-out performance, subject to not exceeding the rollout budget B B : ⟨ Π ∗ , Θ ∗ ⟩ Φ = arg max ⟨ Π , Θ ⟩ Φ 𝔼 ( x , m ) ∼ 𝒯 [ μ ( Φ ( x , ⟨ Π , Θ ⟩ Φ ) , m ) ] , s.t. # rollouts ≤ B . \displaystyle\langle\Pi^{*},\Theta^{*}\rangle_{\Phi}=\arg\max_{\langle\Pi,\Theta\rangle_{\Phi}}\mathbb{E}_{(x,m)\sim\mathcal{T}}\left[\mu\big(\Phi(x;\langle\Pi,\Theta\rangle_{\Phi}),\,m\big)\right],\quad\text{s.t.}\quad\#\text{rollouts}\leq B. (2) The core challenge, then, is: How do we extract maximal learning signal from every expensive rollout to enable effective adaptation of complex, modular AI systems in low-data or budget-constrained settings?
## 3 GEPA: Reflective Prompt Evolution
We introduce GEPA (Genetic-Pareto), a sample-efficient optimizer for compound AI systems motivated by three core principles: genetic prompt evolution (Section 3 ), reflection using natural language feedback (Section 3 ), and Pareto-based candidate selection (Section 3.1 ). Figure 3 gives an overview of GEPA and the full GEPA algorithm is formalized in Figure 4 . GEPA receives the following inputs: A system Φ \Phi instantiated with simple prompts to be optimized, training dataset D t r a i n D_{train} (consisting of task instances ( x , m ) (x,m) as described in Section 2 ), the standard evaluation metric μ \mu for the task, a feedback function μ f \mu_{f} (introduced in Section 3 ) and the total rollout budget B B . Note that GEPA evolves only the set of prompts, denoted as Π Φ \Pi_{\Phi} , whereas the underlying LLM weights, denoted by Θ Φ \Theta_{\Phi} remains fixed.
Genetic Optimization Loop: Given an AI system Φ \Phi , the goal is to identify parameters Π Φ \Pi_{\Phi} that maximize task performance. GEPA begins with a candidate pool 𝒫 \mathcal{P} containing only the base system, where each candidate is a concrete instantiation of ⟨ Π , Θ f r o z e n ⟩ Φ \langle\Pi,\Theta_{frozen}\rangle_{\Phi} . It then enters an optimization loop, repeatedly proposing new candidates until the evaluation budget is exhausted. Candidates are derived from existing ones via reflective mutation or crossover , guided by feedback from rollouts, with each inheriting learning signals from its parents and its own rollout so that GEPA accumulates knowledge along the genetic tree. In each iteration, GEPA (i) selects promising candidates, (ii) proposes and evaluates a variant on a minibatch of tasks, and (iii) if it outperforms its parent(s), adds it to 𝒫 \mathcal{P} with ancestry records and evaluate on D p a r e t o D_{pareto} , the validation set used for selection. After the budget is exhausted, GEPA returns the candidate with the best aggregate performance on D p a r e t o D_{pareto} .
Reflective Prompt Mutation: Natural language traces generated during the execution of a compound AI system offer rich visibility into the behavior and responsibilities of each module, as they capture the intermediate inferences and underlying reasoning steps. When these traces are paired with the final outcome of the system (e.g., success or failure), they provide substantial diagnostic value, allowing practitioners to trace errors or successes back to specific decisions made at the module level. LLMs can leverage these traces via reflection to perform implicit credit assignment, attributing responsibility for the final outcome to the relevant modules. This process of reflection can then be used to make targeted updates to individual modules, making large and effective updates to the whole system’s behavior.
Given a candidate to mutate in the current iteration of the optimization loop (stochastically selected from the Pareto-frontier, see Section 3.1 below), GEPA executes the selected candidate on a stochastically sampled minibatch of input queries from the trainset, tracing the program’s execution. From the execution traces, GEPA extracts the module’s inputs, outputs, and reasoning, and calls the feedback function μ f \mu_{f} , which returns a numeric score and text feedback including details about the evaluation (like compiler error messages, failed rubrics, etc.). GEPA selects the module (among the | M | |M| modules that the language program contains) to be updated based on a policy (round-robin), and a reflection LM is then shown the (current prompt, language program trajectory, score, feedback) with the task to reflectively attribute successes or failures to prompt elements and propose revised instructions. The updated module, with the rest of the language program, is evaluated again on the minibatch, and if the score improves, then the new program is added to the candidate pool. The meta-prompt for reflective prompt updates is shown in Appendix C and the full algorithm is presented in Algorithm 1 .
Evaluation traces as diagnostic signals: The text that LLMs produce is the execution trace of the AI system. The text that the environment produces to compute the reward (e.g. compiler error messages before giving reward 0) is the evaluation trace . Beyond reflection on execution traces, we identify a second valuable source of diagnostic information in the evaluation traces. Many evaluation metrics apply rich strategies (e.g., code evaluation may involve compilation, execution, and profiling), producing natural language traces before computing a scalar reward. We propose leveraging these evaluation traces for reflective credit assignment and targeted prompt updates. GEPA achieves this by extending rewards μ \mu into a feedback function μ f \mu_{f} that extracts textual traces during evaluation and returns them with the final score as feedback_text . When available, such feedback can even be module-specific (e.g. in multi-hop systems the evaluator may provide feedback after each hop). In practice, there are domains where human-graders are able to rate the AI system’s responses, along with providing detailed feedback justifying their scalar ratings. When available, D t r a i n D_{train} can be augmented with such human-written explanations for each instance; during reflection, and GEPA can consume these explanations as auxiliary feedback_text to guide targeted prompt updates, even when natural-language feedback from rollouts is limited or unavailable.
### 3.1 Pareto-based candidate selection