DSPy (Declarative Self-improving Python) is a framework for building LLM-driven systems by writing compositional Python code instead of hand-tuning text prompts. You express the behavior you want as modular components with typed input/output signatures, and DSPy handles turning those into the actual prompts sent to the model.
On top of that programming model, it provides optimizers that automatically tune the prompts and, where applicable, the weights of each module against a metric and example data. The approach is meant to cover a range of systems from simple classifiers to RAG pipelines and multi-step agent loops, letting the same code be re-optimized as models or requirements change rather than rewritten by hand.
