cs.LGApr 6, 2026

Optimizing LLM Prompt Engineering with DSPy Based Declarative Learning

Authors: Shiek Ruksana, Sailesh Kiran Kurra, Thipparthi Sanjay Baradwaj

Organizations: Vasavi College of Engineering, Hyderabad, TS, India · Amazon, Texas, United States of America · Vasavi College of Engineering, Telangana, India

Abstract

Large Language Models (LLMs) have shown strong performance across a wide range of natural language processing tasks; however, their effectiveness is highly dependent on prompt design, structure, and embedded reasoning signals. Conventional prompt engineering methods largely rely on heuristic trial-and-error processes, which limits scalability, reproducibility, and generalization across tasks. DSPy, a declarative framework for optimizing text-processing pipelines, offers an alternative approach by enabling automated, modular, and learnable prompt construction for LLM-based systems.This paper presents a systematic study of DSPy-based declarative learning for prompt optimization, with emphasis on prompt synthesis, correction, calibration, and adaptive reasoning control. We introduce a unified DSPy LLM architecture that combines symbolic planning, gradient free optimization, and automated module rewriting to reduce hallucinations, improve factual grounding, and avoid unnecessary prompt complexity. Experimental evaluations conducted on reasoning tasks, retrieval-augmented generation, and multi-step chain-of-thought benchmarks demonstrate consistent gains in output reliability, efficiency, and generalization across models. The results show improvements of up to 30 to 45% in factual accuracy and a reduction of approximately 25% in hallucination rates. Finally, we outline key limitations and discuss future research directions for declarative prompt optimization frameworks.

Explore similar work

CardsList
  1. Reflective Prompt Tuning through Language Model Function-Calling

    May 20, 2026Farima Fatahi Bayat, Moin Aminnaseri, Pouya Pezeshkpour +1LLM Self-RefinementLLM Prompting

  2. Adaptive Prompt Structure Factorization: A Framework for Self-Discovering and Optimizing Compositional Prompt Programs

    Apr 8, 2026Haoyue Liu, Zhichao Wang, Yongxin Guo +2LLM Input OptimizationLLM Prompting

  3. Generalizable Self-Evolving Memory for Automatic Prompt Optimization

    Mar 23, 2026Guanbao Liang, Yuanchen Bei, Sheng Zhou +5Automatic Prompt OptimizationLanguage Model Self-Improvement