Is It Time To Treat Prompts As Code? A Multi-Use Case Study For Prompt Optimization Using DSPy

Fuente: arXiv
Guardado en:
Detalles Bibliográficos
Autores principales: Lemos, Francisca, Alves, Victor, Ferraz, Filipa
Formato: Preprint
Publicado: 2025
Materias:
Acceso en línea:
Etiquetas: Agregar Etiqueta
Sin Etiquetas, Sea el primero en etiquetar este registro!
_version_ 1866908434472894464
author Lemos, Francisca
Alves, Victor
Ferraz, Filipa
author_facet Lemos, Francisca
Alves, Victor
Ferraz, Filipa
contents Although prompt engineering is central to unlocking the full potential of Large Language Models (LLMs), crafting effective prompts remains a time-consuming trial-and-error process that relies on human intuition. This study investigates Declarative Self-improving Python (DSPy), an optimization framework that programmatically creates and refines prompts, applied to five use cases: guardrail enforcement, hallucination detection in code, code generation, routing agents, and prompt evaluation. Each use case explores how prompt optimization via DSPy influences performance. While some cases demonstrated modest improvements - such as minor gains in the guardrails use case and selective enhancements in hallucination detection - others showed notable benefits. The prompt evaluation criterion task demonstrated a substantial performance increase, rising accuracy from 46.2% to 64.0%. In the router agent case, the possibility of improving a poorly performing prompt and of a smaller model matching a stronger one through optimized prompting was explored. Although prompt refinement increased accuracy from 85.0% to 90.0%, using the optimized prompt with a cheaper model did not improve performance. Overall, this study's findings suggest that DSPy's systematic prompt optimization can enhance LLM performance, particularly when instruction tuning and example selection are optimized together. However, the impact varies by task, highlighting the importance of evaluating specific use cases in prompt optimization research.
format Preprint
id arxiv_https___arxiv_org_abs_2507_03620
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle Is It Time To Treat Prompts As Code? A Multi-Use Case Study For Prompt Optimization Using DSPy
Lemos, Francisca
Alves, Victor
Ferraz, Filipa
Software Engineering
Artificial Intelligence
Computation and Language
Machine Learning
68T50
I.2.7; D.2.3
Although prompt engineering is central to unlocking the full potential of Large Language Models (LLMs), crafting effective prompts remains a time-consuming trial-and-error process that relies on human intuition. This study investigates Declarative Self-improving Python (DSPy), an optimization framework that programmatically creates and refines prompts, applied to five use cases: guardrail enforcement, hallucination detection in code, code generation, routing agents, and prompt evaluation. Each use case explores how prompt optimization via DSPy influences performance. While some cases demonstrated modest improvements - such as minor gains in the guardrails use case and selective enhancements in hallucination detection - others showed notable benefits. The prompt evaluation criterion task demonstrated a substantial performance increase, rising accuracy from 46.2% to 64.0%. In the router agent case, the possibility of improving a poorly performing prompt and of a smaller model matching a stronger one through optimized prompting was explored. Although prompt refinement increased accuracy from 85.0% to 90.0%, using the optimized prompt with a cheaper model did not improve performance. Overall, this study's findings suggest that DSPy's systematic prompt optimization can enhance LLM performance, particularly when instruction tuning and example selection are optimized together. However, the impact varies by task, highlighting the importance of evaluating specific use cases in prompt optimization research.
title Is It Time To Treat Prompts As Code? A Multi-Use Case Study For Prompt Optimization Using DSPy
topic Software Engineering
Artificial Intelligence
Computation and Language
Machine Learning
68T50
I.2.7; D.2.3
url https://arxiv.org/abs/2507.03620