dspy-miprov2-optimizer

dspy-miprov2-optimizer is a skill for Claude Code from OmidZamani/dspy-skills. It costs 33 tokens per session (1,459 once invoked), scanned A, original, MIT.

A DSPy tool for tuning a program’s instructions and example inputs with Bayesian optimization, a method that tests promising settings based on earlier results.

In plain words
What is it for?
Use it to optimize a DSPy program when you have 200 or more training examples, need to tune both instructions and examples, and can run 40 or more trials.
Why use it?
It reduces the manual work of trying different instructions and examples. It is suited to larger training sets and longer optimization runs.

Skill for Claude Code

Written for Claude Code: allowed-tools in frontmatter.

Part of the dspy-skills plugin — 24 skills shipped together

Good fit Use it to optimize a DSPy program when you have 200 or more training examples, need to tune both instructions and examples, and can run 40 or more trials.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/omidzamani/dspy-skills/dspy-miprov2-optimizer
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add OmidZamani/dspy-skills --skill dspy-miprov2-optimizer
Clone the repo
git clone --depth 1 https://github.com/OmidZamani/dspy-skills

Made for: Claude Code.

Or install dspy-skills, the plugin that ships this one along with the rest of its 24 skills.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for dspy-miprov2-optimizer

README.md
[![agentmods](https://agentmods.dev/badge/skills/omidzamani/dspy-skills/dspy-miprov2-optimizer/github.svg)](https://agentmods.dev/skills/omidzamani/dspy-skills/dspy-miprov2-optimizer)
Your own site
<a href="https://agentmods.dev/skills/omidzamani/dspy-skills/dspy-miprov2-optimizer"><img src="https://agentmods.dev/badge/skills/omidzamani/dspy-skills/dspy-miprov2-optimizer/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for dspy-miprov2-optimizer

Your own site · 80×15
<a href="https://agentmods.dev/skills/omidzamani/dspy-skills/dspy-miprov2-optimizer"><img src="https://agentmods.dev/badge/skills/omidzamani/dspy-skills/dspy-miprov2-optimizer.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 33 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,459 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00033 $0.01459
Opus 5 $0.00016 $0.00730
Sonnet 5 $0.00007 $0.00292
Haiku 4.5 $0.00003 $0.00146

Measured 12d ago against content hash a29f3fe39285, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-12, from the pricing page.

Security

Grade A, and why

dspy-miprov2-optimizer scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 12d ago.

The scan reads SKILL.md. This mod also ships 1 executable file (example.py), listed below but not scanned — reading those needs a real analyzer, not pattern matching.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/dspy-miprov2-optimizer/SKILL.md · 213 lines

How it starts

The opening of the file, as written. The whole thing — 213 lines — stays where its author put it; the contents beside it link to each section on GitHub.

DSPy MIPROv2 Optimizer

Goal

Jointly optimize instructions and few-shot demonstrations using Bayesian Optimization for maximum performance.

When to Use

  • You have 200+ training examples
  • You can afford longer optimization runs (40+ trials)
  • You need state-of-the-art performance
  • Both instructions and demos need tuning

Inputs

Input Type Description
program dspy.Module Program to optimize
trainset list[dspy.Example] 200+ training examples
metric callable Evaluation function
auto str "light", "medium", or "heavy"
num_trials int Optimization trials (40+)

Outputs

Output Type Description
compiled_program dspy.Module Fully optimized program

Workflow

Install the optional Optuna dependency before using MIPROv2:

pip install -U "dspy[optuna]>=3.2.1,<3.3"

Three-Stage Process

  1. Bootstrap - Generate candidate demonstrations
  2. Propose - Create grounded instruction candidates
  3. Search - Bayesian optimization over combinations

Phase 1: Setup

import dspy
from dspy.teleprompt import MIPROv2

lm = dspy.LM('openai/gpt-4o-mini')
dspy.configure(lm=lm)

Phase 2: Define Program

class RAGAgent(dspy.Module):
    def __init__(self):
        self.retrieve = dspy.Retrieve(k=3)
        self.generate = dspy.ChainOfThought("context, question -> answer")
    
    def forward(self, question):
        context = self.retrieve(question).passages
        return self.generate(context=context, question=question)

Phase 3: Optimize

from dspy.teleprompt import MIPROv2

optimizer = MIPROv2(
    metric=dspy.evaluate.answer_exact_match,
    auto="medium",  # Balanced optimization
    num_threads=24
)

compiled = optimizer.compile(RAGAgent(), trainset=trainset)

Read the full file on GitHub · 213 lines

Files

What ships with it

1 file beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 12d ago First seen · 213 lines · 33 tokens per session scan A a29f3fe39285

Subscribe to this mod's changes

dspy-miprov2-optimizer is a skill published in the GitHub repository OmidZamani/dspy-skills (123 stars, last pushed 2mo ago), licensed MIT. It adds 33 tokens to every session and 1,459 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.