AI tool

DSPy

Visit website

Use DSPy when you can define a scoring function and examples before optimising a language-model pipeline.

Starting price
MIT software; inference extra
Free access
Library free; model calls separate
Billing unit
Your model tokens and optimisation runs
Platform
Python package in your environment
Verified
29 Oct 2026

Overview

What you provide

  • Define task signatures, representative examples, an approved model connection and a metric that reflects useful outputs.

What you get

  • DSPy returns structured predictions and reusable optimized program configurations rather than a hosted finished application.

Choosing this tool

DSPy is useful for extraction, retrieval or agent programs whose behaviour should improve against a measurable task. Typed signatures declare inputs and outputs; modules choose execution strategies and optimizers tune prompts against examples. Pydantic AI is a closer choice for typed tools and an application agent loop, while LangChain offers a wider integration-oriented orchestration stack. Optimizing against a weak or leaked metric can improve a score without improving real task quality.

A decision worked through

If an optimization evaluates fifty candidates on twenty examples, that can involve roughly one thousand example evaluations before retries or a more complex module’s extra calls. Estimate the actual call graph and provider rates; a free library does not make that experiment free.

DSPy alternatives for metric-driven optimisation of llm programs

Compare DSPy with PydanticAI, LangChain by the actual task, billing unit and operating responsibility.

ProductPrice / unitFree allowanceInput → outputKey limit
DSPyRead profileOfficial source ↗MIT software; inference extraNo bundled model-call quotaExamples and metrics produce optimized programs.Optimization can multiply model calls.
PydanticAIRead profileOfficial source ↗Open-source SDK; provider fees separateOffline test model availableTyped requests become validated Python results.Durability needs a configured backend.
LangChainRead profileOfficial source ↗MIT library; models and hosted services extraOpen-source package without inference creditsModels, tools and data form application workflows.Provider adapters do not unify every model capability.

Setup & workflow

  1. Implement a minimal signature and test it on a few known examples.
  2. Write a metric and split training examples from the held-out set.
  3. Run a bounded optimization and compare unseen failures before deployment.
Requirements & installation
  • Use Python 3.10+ and install the package, then configure a model or local endpoint and bounded evaluation data.

Limits & review

  • Optimizers consume model calls and can overfit examples. Typed output structure does not establish factual correctness, and external tools retain their own permissions and charges.

Your part

  • Keep a held-out evaluation set and inspect failure cases before deploying an optimized program.
Sources & verification5

This profile is based on official sources, not a hands-on product test.

Vendor descriptions and demos document advertised features. Editorial guidance is based on these sources.