dspy

Installation
SKILL.md

dspy

DSPy is a framework for programming language models instead of prompting them by hand. You declare the task as a typed signature, run it with a module, and let an optimizer rewrite the prompts (and pick few-shot examples) automatically by scoring against a metric. GEPA is the reflective-evolutionary optimizer in that ecosystem and is usually the highest-leverage one for verifiable domains.

As of 2026-06, DSPy and GEPA APIs are evolving (GEPA was accepted at ICLR 2026). Verify against https://dspy.ai/ and https://github.com/gepa-ai/gepa before making version-sensitive recommendations.

Start Here

  1. Inspect the local project first: is DSPy already configured (dspy.configure(lm=...)), what models are wired, is there a dataset and a scoring function, and is anyone hand-writing prompts that could be optimized instead.
  2. Decide what is actually being asked: writing a DSPy program, choosing/running an optimizer, debugging why optimization did not help, or porting a working prompt to a cheaper model. The optimizer choice and the metric design follow from this.
  3. Express the task as a signature, not a prompt string. Put the task guidance in the signature docstring, because that is the surface GEPA and the instruction optimizers rewrite (see Optimizable Surface below).
  4. Pick a module: dspy.Predict for direct mapping, dspy.ChainOfThought when intermediate reasoning helps, dspy.ReAct when the task needs tools.
  5. Write a metric. For GEPA it must return a score and natural-language feedback. The feedback is what makes reflective optimization work, so invest here.
  6. Optimize with a small train/val split, then evaluate the compiled program on held-out data and save it. Treat optimized prompts as versioned build artifacts, not source you edit by hand.

Core Program Shape

import dspy
Installs
4
First Seen
Jun 20, 2026