PROVIDER - Declarative prompt and model programming framework

DSPy

DSPy from a Stanford team declares inputs and outputs through Signatures, letting 1 definition swap models and prompting strategies while 3 optimiser families search better prompt and example combinations; the upfront evaluation set and optimisation quota are the costs.

AI Platform United States 2026.11.19
3.8pts

Detailed Notes

Pros 5 items

Declares inputs and outputs with a Signature, so 1 definition can swap models and prompting strategies
Provides 3 optimiser families that search better prompt and example combinations from a small sample
Turns hand-written prompt strings into compilable programs that survive 2 rounds of refactoring
Compatible with mainstream model services and retrieval components, dropping into 1 existing RAG pipeline unchanged
Maintained by a Stanford team with 2 core papers and matching courses behind the method

Cons 4 items

Requires an evaluation set and metrics, a higher upfront cost than writing prompts directly
Optimisation runs consume model call quota
The abstraction stack is not immediately intuitive for newcomers
Ecosystem and surrounding tooling are still maturing

Service Overview

DSPy is a declarative prompt programming framework from a Stanford team that turns prompt engineering from hand-written strings into compilable, optimisable programs.

In the AI platform category it is the prompting and model programming layer, suited to pipelines that need stable quality and continuous iteration.

Key Strengths

  • Declarative definitions: Signatures describe I/O
  • Automatic optimisation: 3 optimiser families
  • Compilable programs: prompts as assets
  • Ecosystem fit: embeds into existing RAG
  • Academic grounding: papers and courses

Product Ecosystem

Platform capabilities

Signature and Module definitions, optimisers and metric evaluation, automatic example selection, multi-model adaptation, retrieval module composition plus comparison and regression evaluation.

Integrations

Supports mainstream model services and self-hosted endpoints, composing with vector stores and retrieval frameworks.

Typical scenarios

RAG quality tuning, classification and extraction tasks, multi-step reasoning pipelines and prompt regression tests.

Limitations

  • Upfront work: evaluation sets and metrics
  • Optimisation cost: quota consumed by search
  • Concept barrier: abstractions not obvious
  • Ecosystem maturity: tooling still filling out

Use Cases

  • Quality-driven RAG (★★★★☆): clear optimisation gains
  • Regressible prompt iteration (★★★★☆): tested like code
  • Fast prototyping (★★★☆☆): manual prompts are quicker
  • Tight compute budgets (★★☆☆☆): optimisation needs quota

Pricing

Item Price Notes
Open source framework $0 MIT licence, free to use
Model calls Usage based Determined by the chosen model service
Enterprise support Contact sales Available through community or consultants

FAQ

Does DSPy replace prompt engineering?

It compiles and optimises prompts, but humans still define tasks and metrics.

Is a dataset required?

The optimisation step needs a small labelled sample and evaluation metrics.

Does it support local models?

Yes, self-hosted OpenAI-compatible endpoints work.

How does it relate to LangChain?

DSPy can live inside pipelines built with LangChain or LlamaIndex.

Code Examples

import dspy

lm = dspy.LM("openai/gpt-4o-mini")
dspy.configure(lm=lm)

class QA(dspy.Signature):
    """Answer the question from the context."""
    context: str = dspy.InputField()
    question: str = dspy.InputField()
    answer: str = dspy.OutputField()

qa = dspy.Predict(QA)
print(qa(context="Refunds must be requested within 7 days.", question="How long is the refund window?").answer)
# Install DSPy
pip install -U dspy

Community & Resources

Visit DSPy Website → https://dspy.ai/
Visit Website ↗