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.
翻译:大型语言模型(LLM)在广泛的自然语言处理任务中展现了卓越性能,但其有效性高度依赖于提示设计、结构及嵌入的推理信号。传统提示工程方法主要依赖启发式试错过程,这限制了跨任务的可扩展性、可复现性和泛化能力。DSPy作为一个用于优化文本处理管线的声明式框架,通过实现LLM系统自动化、模块化且可学习的提示构建,提供了一种替代方案。本文系统研究了基于DSPy声明式学习的提示优化方法,重点涵盖提示合成、修正、校准及自适应推理控制。我们提出一种统一的DSPy LLM架构,融合符号规划、无梯度优化和自动化模块重写,以减少幻觉、增强事实依据并避免不必要的提示复杂性。在推理任务、检索增强生成及多步思维链基准上的实验评估表明,该架构在输出可靠性、效率和跨模型泛化性方面均取得一致提升。结果显示,事实准确率提升达30%至45%,幻觉率降低约25%。最后,我们概述了关键局限性,并讨论了声明式提示优化框架的未来研究方向。