Skip to main content
DSPy (Declarative Self-improving Python) is a framework for programmatically building and optimizing language model pipelines. Instead of manually tuning brittle prompt strings, you define structured input/output Signatures and compose workflows using modules like Predict, ChainOfThought, or ReAct. DSPy automatically compiles and optimizes prompt instructions and few-shot demonstrations against your evaluation metrics.

Setup

Install the DSPy library:

Client Configuration

Initialize your language model using the dspy.LM class with the neosantara/<model> prefix.

Basic Modules: Predict and ChainOfThought

ReAct Agent with Tools

Use dspy.ReAct to build autonomous agents that invoke Python tools before synthesizing a final answer.

Next Steps