dspy-optimization
DSPy Optimization
Guidance for optimizing DSPy programs: teleprompter selection, metric definition, evaluation workflows, and save/load patterns.
Environment Setup
This skill requires uv as the Python package manager.
uv venv
source .venv/bin/activate
uv pip install dspy
Rule: Never use raw
pip. Always useuv pipfor installs anduv runfor script execution.
Quick Start
Optimizing with metrics
# Use the optimize-dspy script
uv run scripts/optimize-dspy.py --module my_module --metric my_metric --examples examples.jsonl
BootstrapFewShot
from dspy.teleprompt import BootstrapFewShot
optimizer = BootstrapFewShot(metric=my_metric, max_bootstrapped_demos=4)
compiled = optimizer.compile(program, trainset=trainset)
compiled.save("./compiled/program.json")
When to Use This Skill
Use this skill when:
- Running DSPy optimization or compilation with teleprompters
- Defining custom metrics for DSPy evaluation
- Evaluating DSPy programs with dev sets
- Choosing between BootstrapFewShot, MIPROv2, or other optimizers
- Saving and loading compiled programs
Core Concepts
Optimization Reference
See optimization.md for:
- Teleprompter selection guide (BootstrapFewShot, MIPROv2, etc.)
- Metric definition patterns
- Optimization strategies and hyperparameters
- Evaluation and testing workflows
- Save/load best practices (
.save()/.load(), never raw pickle)
Scripts
- optimize-dspy.py: Run optimization with custom metrics and teleprompters
Critical Rules
- Always use
uv:uv pipfor installs,uv runfor scripts - Use
.save()/.load(): Never use rawpicklefor DSPy programs - Use
dspy.LM: Never use deprecateddspy.OpenAIordspy.settings.configure - Mark inputs on examples: Always call
.with_inputs()ondspy.Example
Related Skills
- dspy-core: Signatures, modules, programs, and compilation fundamentals
- dspy-fleet-rlm: fleet-rlm-specific DSPy patterns and integration
Progressive Disclosure
- SKILL.md (this file): Quick reference and navigation
- references/: Detailed optimization docs loaded as needed
- scripts/: Executable optimization tools
More from qredence/skills
agent-converter
Converts agent definitions between Markdown (with YAML frontmatter) and TOML formats. Use when transforming agent configurations for different agent systems — MD format for rich tool restrictions, TOML format for Codex-style agents with sandbox modes.
14dspy-core
Core DSPy framework guidance — signatures, modules, programs, compilation, and testing. Use when creating DSPy signatures, building modules, compiling programs, or learning DSPy fundamentals.
7dspy-gepa
>-
7dspy-fleet-rlm
fleet-rlm-specific DSPy patterns, debugging, and integration with the qredence/fleet-rlm-dspy codebase. Use when working on fleet-rlm DSPy modules, debugging fleet-rlm DSPy issues, or following fleet-rlm architecture conventions.
7babysit-pr
Babysits a GitHub pull request by continuously polling CI checks, review comments, and mergeability state until the PR is ready to merge or closed. Diagnoses failures, retries flaky failures up to 3 times, auto-fixes branch-related issues, and stops only when user help is required. Use when asked to monitor a PR, watch CI, handle review comments, or track failures on an open PR.
7fastapi-router-py
Creates FastAPI routers with CRUD operations, authentication dependencies, and proper response models. Use when building REST API endpoints, creating new routes, implementing CRUD operations, or adding authenticated endpoints in FastAPI applications.
7