Build and auto-optimize declarative LM programs, RAG pipelines, and AI agents using DSPy — no manual prompt engineering required.
DSPy is a Stanford NLP framework for building AI systems as declarative programs rather than hand-crafted prompts. Instead of manually tuning prompt text, you define typed signatures and compose modules — then let DSPy optimizers tune everything automatically using your data and a metric. It supports RAG pipelines, multi-step agents, structured extraction, and works across OpenAI, Anthropic, and local LMs.
npx clawhub@latest install dspyClick the Install button at the top of this page for one-click setup
Define task inputs and outputs as typed Python classes. DSPy constructs and manages prompts from these signatures automatically, keeping your code readable and independent of prompt wording.
Predict, ChainOfThought, ReAct, and ProgramOfThought are drop-in building blocks. Combine them into custom dspy.Module subclasses to express multi-step reasoning pipelines cleanly.
Optimizers like BootstrapFewShot and MIPRO use your labeled examples and a metric function to iteratively improve prompts and few-shot demonstrations — replacing manual trial-and-error with a data-driven loop.
Configure OpenAI, Anthropic Claude, or local Ollama models with a single dspy.settings.configure(lm=...) call. You can even use different models for different stages of the same pipeline via context managers.
Built-in dspy.Retrieve integrates with vector stores like ChromaDB. ReAct enables tool-using agents. Both patterns compose naturally with optimizers for end-to-end improvement.
TypedPredictor accepts Pydantic models as output fields, giving you schema-validated, strongly-typed responses from any LM — no post-processing parsing required.
Wrap a ChainOfThought module in BootstrapFewShot, supply a small labeled dataset, and get a prompt-optimized QA system that measurably outperforms its untuned baseline.
Combine dspy.Retrieve with ChromaDB and a ChainOfThought answer generator. Optimize the full RAG pipeline end-to-end using training examples and an F1 or exact-match metric.
Use ReAct to build agents that call external tools (search, calculators, APIs) in a structured reasoning loop, with DSPy managing the think-act-observe cycle.
Define a Pydantic model for the fields you need (names, dates, amounts) and use TypedPredictor to extract validated structured data from unstructured text reliably.
pip install dspy — core librarypip install dspy[openai], dspy[anthropic], or dspy[all]OPENAI_API_KEY or ANTHROPIC_API_KEY environment variable)pip install chromadb) for RAG retrieval pipelinesLog in to write a review
No reviews yet. Be the first to share your experience!