DSPy (Declarative Self-improving Python) is a modular programming framework designed to transition from manual prompt engineering to systematic optimization of language model (LM) systems. Rather than relying on brittle, hand-written prompts, the framework enables developers to write compositional Python code to build complex AI architectures, including classifiers, Retrieval-Augmented Generation (RAG) pipelines, and autonomous agent loops. DSPy works by compiling declarative LM calls into self-improving pipelines, treating prompts and demonstrations as auto-optimized hyperparameters. The underlying research presents several algorithmic approaches to enhance performance, such as GEPA (Reflective Prompt Evolution), which aims to outperform reinforcement learning, and methods for optimizing both instructions and demonstrations within multi-stage programs. Key methodologies documented include "Demonstrate-Search-Predict" for knowledge-intensive NLP tasks and the integration of fine-tuning with prompt optimization to create more robust systems. By treating the LM interaction as a programmable component, DSPy allows for iterative refinement of weights and instructions through automated algorithms, shifting the focus from linguistic prompting to programmatic, algorithmic optimization of language model pipelines.

Read original