PRewrite: Prompt Rewriting with Reinforcement Learning
Weize Kong, Spurthi Amba Hombaiah, Mingyang Zhang, Qiaozhu Mei, Michael Bendersky
TL;DR
The paper tackles the challenge of manual prompt engineering for large language models by introducing PRewrite, a prompt rewriting framework trained with reinforcement learning. A rewriter LLM, guided by a meta prompt, learns to rewrite an under-optimized instruction into a more effective one, which the task LLM then uses to generate outputs; the rewriter is fine-tuned via PPO with KL penalties using rewards based on downstream task performance. Two rewriting strategies—inference (single prompt) and search (multiple prompts with dev-based selection)—enable robust prompt optimization while preserving interpretability. Empirical results on AG News, SST-2, NQ, and GSM8K with PaLM 2-S/L demonstrate consistent improvements over baselines and state-of-the-art performance on GSM8K, highlighting the method’s scalability to API-accessible, larger LLMs and its potential to reduce manual engineering effort. The work contributes a general, RL-based approach to automated prompt optimization that produces interpretable rewrites and can adapt to evolving models.
Abstract
Prompt engineering is critical for the development of LLM-based applications. However, it is usually done manually in a "trial and error" fashion that can be time consuming, ineffective, and sub-optimal. Even for the prompts which seemingly work well, there is always a lingering question: can the prompts be made better with further modifications? To address these problems, we investigate automated prompt engineering in this paper. Specifically, we propose PRewrite, an automated method to rewrite an under-optimized prompt to a more effective prompt. We instantiate the prompt rewriter using a LLM. The rewriter LLM is trained using reinforcement learning to optimize the performance on a given downstream task. We conduct experiments on diverse benchmark datasets, which demonstrates the effectiveness of PRewrite.
