Is It Time To Treat Prompts As Code? A Multi-Use Case Study For Prompt Optimization Using DSPy
On the map: LLM safety and security → Prompt injection and agent security
Abstract (arXiv)
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.
Key facts. Cited by 1 paper in the map (data through 14 Oct 2026). Placed in Prompt injection and agent security, one of 12 directions in LLM safety and security. Builds on 17 of its 28 references that are in the map. First posted on arXiv 4 Jul 2025.
Builds on
17 of 28 references.
References · 17
- 2023Tree of Thoughts: Deliberate Problem Solving with Large Language Modelscited by 3,211
- 2024A Survey on LLM-as-a-Judgecited by 1,423
- 2022Large Language Models Are Human-Level Prompt Engineerscited by 1,045
- 2023Large Language Models as Optimizerscited by 864
- 2024From Generation to Judgment: Opportunities and Challenges of LLM-as-a-judgecited by 494
- 2024LLMs-as-Judges: A Comprehensive Survey on LLM-based Evaluation Methodscited by 465
- 2024A Systematic Survey of Prompt Engineering in Large Language Models: Techniques and Applicationscited by 431
- 2024Optimizing Instructions and Demonstrations for Multi-Stage Language Model Programscited by 291
- 2024TextGrad: Automatic "Differentiation" via Textcited by 273
- 2023Challenges and Applications of Large Language Modelscited by 254
- 2023Large Language Model Guided Tree-of-Thoughtcited by 221
- 2023EvoPrompt: Connecting LLMs with Evolutionary Algorithms Yields Powerful Prompt Optimizerscited by 193
5 more
- 2023Unleashing the potential of prompt engineering for large language modelscited by 72
- 2024Building Guardrails for Large Language Modelscited by 65
- 2024CodeJudge: Evaluating Code Generation with Large Language Modelscited by 44
- 2023Automatic Engineering of Long Promptscited by 14
- 2025LangProBe: a Language Programs Benchmarkcited by 2
Built on by
Citing papers per year: 2025: 1.
1 paper.
Similar, not cited
Close in wording, no citation either way
- 2025Is Your Prompt Poisoning Code? Defect Induction Rates and Security Mitigation Strategies
- 2026Optimizing LLM Prompt Engineering with DSPy Based Declarative Learning
- 2025Prompt engineering and framework: implementation to increase code reliability based guideline for LLMs
- 2024A Comparative Study of DSPy Teleprompter Algorithms for Aligning Large Language Models Evaluation Metrics to Human Evaluation
- 2025Has My System Prompt Been Used? Large Language Model Prompt Membership Inference
- 2026Reflective Prompt Tuning through Language Model Function-Calling
- 2024PRompt Optimization in Multi-Step Tasks (PROMST): Integrating Human Feedback and Heuristic-based Sampling
- 2023DSPy: Compiling Declarative Language Model Calls into Self-Improving Pipelines