Quickstart
Get your first optimized prompt in under 5 minutes
Quickstart
Three steps: define your task, write a metric, call optimize(). That's it.
Installation
Set Your API Keys
Example: Customer Support Routing
GPT-4o-mini confuses billing and account tickets — password resets get routed to billing, invoice questions go to account. The optimizer learns the boundary from your labelled examples.
What Happens
- Baseline — the model conflates account management with billing because the instructions don't distinguish them
- Contrastive mining — the optimizer finds bad→good pairs (e.g. password reset labelled
account, notbilling) and extracts rules from the difference - Rule validation — each candidate rule is tested on held-out examples; rules that hurt performance are discarded
- Result — the optimized module's instructions now include precise team definitions extracted from your data
Key Concepts
| Concept | Description |
|---|---|
| Module | A DSPy module wrapping your LLM task (Signature + Predict/ChainOfThought) |
| Metric | Scores each prediction. Returns a vizpy.Score with value, is_success, and feedback |
| Feedback | The most critical field — tells the optimizer why a prediction is wrong. Richer feedback → better rules |
| Train examples | Input-only dicts the optimizer learns from. Store expected outputs in your metric |