How to build your first DSPy program and optimize it
Quando usar: You have a task where prompt quality matters and want a systematic way to improve it.
Pré-requisitos
- Python 3.10+ with dspy-ai installed — pip install dspy-ai
- Skill cloned — git clone https://github.com/OmidZamani/dspy-skills ~/.claude/skills/dspy-skills
Fluxo
-
Define the signatureTask: classify support tickets into {billing, technical, account}. Give me a DSPy signature and a simple Predict module.✓ Copiado→ Signature + module code
-
Write an evalAdd an evaluation set of 50 labeled examples and an accuracy metric.✓ Copiado→ Eval harness with metric callable
-
OptimizeRun BootstrapFewShot to compile the module against the eval set.✓ Copiado→ Compiled predictor + improved score
Resultado: A DSPy-optimized predictor that beats a hand-written prompt, with reproducible code.
Armadilhas
- Eval too small — optimizer overfits — Minimum 100–200 examples; hold out a true test set
- Metric doesn't capture what you care about — Spend on metric design before on model choice