How to build your first DSPy program and optimize it
언제 쓸까: You have a task where prompt quality matters and want a systematic way to improve it.
사전 조건
- 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
흐름
-
Define the signatureTask: classify support tickets into {billing, technical, account}. Give me a DSPy signature and a simple Predict module.✓ 복사됨→ Signature + module code
-
Write an evalAdd an evaluation set of 50 labeled examples and an accuracy metric.✓ 복사됨→ Eval harness with metric callable
-
OptimizeRun BootstrapFewShot to compile the module against the eval set.✓ 복사됨→ Compiled predictor + improved score
결과: A DSPy-optimized predictor that beats a hand-written prompt, with reproducible code.
함정
- 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