Automatic Prompt Optimization with "Gradient Descent" and Beam Search
Reid Pryzant, Dan Iter, Jerry Li, Yin Tat Lee, Chenguang Zhu, Michael Zeng
Abstract
Large Language Models (LLMs) have shown impressive performance as general purpose agents, but their abilities remain highly dependent on prompts which are hand written with onerous trial-and-error effort. We propose a simple and nonparametric solution to this problem, Prompt Optimization with Textual Gradients (ProTeGi), which is inspired by numerical gradient descent to automatically improve prompts, assuming access to training data and an LLM API. The algorithm uses minibatches of data to form natural language "gradients" that criticize the current prompt, much like how numerical gradients point in the direction of error ascent. The natural language gradients are then "propagated" into the prompt by editing the prompt in the opposite semantic direction of the gradient. These gradient descent steps are guided by a beam search and bandit selection procedure which significantly improves algorithmic efficiency. Preliminary results across three benchmark NLP tasks and the novel problem of LLM jailbreak detection suggest that Automatic Prompt Optimization can outperform prior prompt editing techniques and improve an initial prompt's performance by up to 31%, by using data to rewrite vague task descriptions into more precise annotation instructions. 1
Ask Lune
Know this paper in minutes, not an afternoon.
Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.
156 top-tier papers have cited it since. Know what they found before your reviewers do.
Lune can draw on
the full paper · the top-tier papers that cite it · related work
Free to start. No credit card required.
Lineage
- Quantifying Language Models' Sensitivity to Spurious Features in Prompt Design or: How I learned to start worrying about prompt formatting cites Fantastically Ordered Prompts and Where to Find Them: Overcoming Few-Shot Prompt Order Sensitivity
- Quantifying Language Models' Sensitivity to Spurious Features in Prompt Design or: How I learned to start worrying about prompt formatting cites Large Language Models are Human-Level Prompt Engineers
- Reflexion: language agents with verbal reinforcement learning cites Teaching Large Language Models to Self-Debug
- Promptbreeder: Self-Referential Self-Improvement via Prompt Evolution cites Fantastically Ordered Prompts and Where to Find Them: Overcoming Few-Shot Prompt Order Sensitivity
- Promptbreeder: Self-Referential Self-Improvement via Prompt Evolution cites Large Language Models as Optimizers
- Large Language Models as Optimizers cites Promptbreeder: Self-Referential Self-Improvement via Prompt Evolution
- Promptbreeder: Self-Referential Self-Improvement via Prompt Evolution cites Large Language Models are Human-Level Prompt Engineers
- Large Language Models as Optimizers cites Fantastically Ordered Prompts and Where to Find Them: Overcoming Few-Shot Prompt Order Sensitivity
- Large Language Models as Optimizers cites Teaching Large Language Models to Self-Debug
- Large Language Models as Optimizers cites Large Language Models are Human-Level Prompt Engineers
- Optimizing Prompts for Text-to-Image Generation cites Large Language Models are Human-Level Prompt Engineers
- Large Language Models are Human-Level Prompt Engineers cites Fantastically Ordered Prompts and Where to Find Them: Overcoming Few-Shot Prompt Order Sensitivity
- GEPA: Reflective Prompt Evolution Can Outperform Reinforcement Learning cites Reflexion: language agents with verbal reinforcement learning
- GEPA: Reflective Prompt Evolution Can Outperform Reinforcement Learning cites Promptbreeder: Self-Referential Self-Improvement via Prompt Evolution
- GEPA: Reflective Prompt Evolution Can Outperform Reinforcement Learning cites Large Language Models as Optimizers
- GEPA: Reflective Prompt Evolution Can Outperform Reinforcement Learning cites Large Language Models are Human-Level Prompt Engineers
Cited by top-tier papers156
- Reflexion: language agents with verbal reinforcement learningNoah Shinn, Federico Cassano, Ashwin Gopinath, Karthik Narasimhan et al.NeurIPS 2023 · 5,828 citations
- Large Language Models as OptimizersChengrun Yang, Xuezhi Wang, Yifeng Lu, Hanxiao Liu et al.ICLR 2024 · 817 citations
- Quantifying Language Models' Sensitivity to Spurious Features in Prompt Design or: How I learned to start worrying about prompt formattingMelanie Sclar, Yejin Choi, Yulia Tsvetkov, Alane SuhrICLR 2024 · 682 citations
- GEPA: Reflective Prompt Evolution Can Outperform Reinforcement LearningLakshya A. Agrawal, Shangyin Tan, Dilara Soylu, Noah Ziems et al.ICLR 2026 · 466 citations
- Promptbreeder: Self-Referential Self-Improvement via Prompt EvolutionChrisantha Fernando, Dylan Banarse, Henryk Michalewski, Simon Osindero et al.ICML 2024 · 432 citations
Builds on12
- Fantastically Ordered Prompts and Where to Find Them: Overcoming Few-Shot Prompt Order SensitivityYao Lu, Max Bartolo, Alastair Moore, Sebastian Riedel et al.ACL 2022 · 1,494 citations
- Teaching Large Language Models to Self-DebugXinyun Chen, Maxwell Lin, Nathanael Schärli, Denny ZhouICLR 2024 · 1,085 citations
- Why Johnny Can't Prompt: How Non-AI Experts Try (and Fail) to Design LLM PromptsJ. D. Zamfirescu-Pereira, Richmond Y. Wong, Bjoern Hartmann, Qian YangCHI 2023 · 892 citations
- Optimizing Prompts for Text-to-Image GenerationYaru Hao, Zewen Chi, Li Dong, Furu WeiNeurIPS 2023 · 303 citations
- Large Language Models are Human-Level Prompt EngineersYongchao Zhou, Andrei Ioan Muresanu, Ziwen Han, Keiran Paster et al.ICLR 2023 · 297 citations
Related papers
- Unleashing the Potential of Large Language Models as Prompt Optimizers: Analogical Analysis with Gradient-based Model OptimizersXinyu Tang, Xiaolei Wang, Wayne Xin Zhao, Siyuan Lu et al.AAAI 2025 · 36 citations
- PRompt Optimization in Multi-Step Tasks (PROMST): Integrating Human Feedback and Heuristic-based SamplingYongchao Chen, Jacob Arkin, Yilun Hao, Yang Zhang et al.EMNLP 2024 · 6 citations
- GReaTer: Gradients Over Reasoning Makes Smaller Language Models Strong Prompt OptimizersSarkar Snigdha Sarathi Das, Ryo Kamoi, Bo Pang, Yusen Zhang et al.ICLR 2025
- metaTextGrad: Automatically optimizing language model optimizersGuowei Xu, Mert Yüksekgönül, Carlos Guestrin, James Y. ZouNeurIPS 2025 · 5 citations
- Task Facet Learning: A Structured Approach To Prompt OptimizationGurusha Juneja, Gautam Jajoo, Hua Li, Jian Jiao et al.ACL Findings 2025 · 3 citations
