Skip to content
BENIBIX Learn

DSPy

Development🧬 AI EngineeringLLM Frameworks

Also known as DSPy Framework, Stanford DSPy

A Python kit. You say what goes in and out, and it writes the prompts.

Think of it like

It is like a cook who tries a dish many ways and keeps the best.

Example

Jack's team declares email in, event name and date out. The optimizer tries prompt wording on 50 labeled emails and keeps the version that scores best.

Why it matters

Hand-written prompts often break when you change models. DSPy keeps the task the same and tunes the wording again for the new model.

Definition

DSPy is a free, open-source Python framework that writes your prompts for you. You declare a task as a signature: what goes in and what comes out. A module decides how to run it, such as a plain answer, step by step reasoning or a tool loop. An optimizer takes your examples and a scoring rule. It then tunes the prompts to score higher. DSPy began at Stanford.

Example code

python
import dspy

dspy.configure(lm=dspy.LM("openai/gpt-5.4-nano"))
extract = dspy.Predict("email -> event_name, date")
result = extract(email="Lunch with Emma on May 3 at noon")
The signature says what goes in and what comes out. DSPy writes the prompt.
DSPy is the one built around tuning prompts from examples.

Common mistake

Running an optimizer with a weak scoring rule. It tunes toward what the score rewards, even when that is the wrong thing.

Key takeaways

  1. 1
    Signatures. Inputs and outputs, not wording.
  2. 2
    Modules. How the task is run.
  3. 3
    Optimizers. Tune prompts from examples.