dspy-better-together

dspy-better-together is a skill for Claude Code from OmidZamani/dspy-skills. It costs 32 tokens per session (775 once invoked), scanned A, original, MIT.

A DSPy workflow that tries prompt optimization and model-weight optimization in sequence, evaluates the intermediate results, and returns the best candidate.

In plain words
What is it for?
Use it to optimize DSPy programs with a validation set, supported language-model fine-tuning, and strategies such as prompt-to-weights-to-prompt.
Why use it?
It helps compare different improvement strategies instead of relying on only prompt changes or only fine-tuning.

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 DSPy programs with a validation set, supported language-model fine-tuning, and strategies such as prompt-to-weights-to-prompt.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/omidzamani/dspy-skills/dspy-better-together
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-better-together
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-better-together

README.md
[![agentmods](https://agentmods.dev/badge/skills/omidzamani/dspy-skills/dspy-better-together/github.svg)](https://agentmods.dev/skills/omidzamani/dspy-skills/dspy-better-together)
Your own site
<a href="https://agentmods.dev/skills/omidzamani/dspy-skills/dspy-better-together"><img src="https://agentmods.dev/badge/skills/omidzamani/dspy-skills/dspy-better-together/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-better-together

Your own site · 80×15
<a href="https://agentmods.dev/skills/omidzamani/dspy-skills/dspy-better-together"><img src="https://agentmods.dev/badge/skills/omidzamani/dspy-skills/dspy-better-together.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 32 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 775 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.00032 $0.00775
Opus 5 $0.00016 $0.00387
Sonnet 5 $0.00006 $0.00155
Haiku 4.5 $0.00003 $0.00077

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

Security

Grade A, and why

dspy-better-together 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-better-together/SKILL.md · 107 lines

How it starts

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

DSPy BetterTogether

Goal

Sequence prompt and weight optimizers, evaluate intermediate programs, and return the best candidate.

Prerequisites

  • Use DSPy 3.2.1 or later in the stable 3.2.x series.
  • Assign an LM directly to every predictor with student.set_lm(lm).
  • Keep a validation set, or allow BetterTogether to hold out part of the trainset.
  • Confirm the LM provider supports fine-tuning before including BootstrapFinetune.

Basic Pattern

import dspy

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

student = dspy.ChainOfThought("question -> answer")
student.set_lm(lm)

def metric(example, pred, trace=None):
    return float(example.answer.lower() == pred.answer.lower())

optimizer = dspy.BetterTogether(
    metric=metric,
    p=dspy.GEPA(
        metric=lambda gold, pred, trace=None, pred_name=None, pred_trace=None:
            dspy.Prediction(score=metric(gold, pred), feedback="Check answer correctness."),
        reflection_lm=dspy.LM("openai/gpt-4o"),
        auto="light",
    ),
    w=dspy.BootstrapFinetune(metric=metric),
)

compiled = optimizer.compile(
    student,
    trainset=trainset,
    valset=valset,
    strategy="p -> w -> p",
)

Strategy Choices

Strategy Use it when
"p -> w" Start with a simple prompt-then-weight pass
"p -> w -> p" Re-optimize prompts after fine-tuning
"w -> p" Fine-tuning data is already strong
Custom chains Comparing prompt optimizers or conducting controlled experiments

Optimizer names come from constructor keyword arguments. For example, mipro=... and gepa=... make "mipro -> gepa" valid.

Per-Optimizer Compile Arguments

Pass optimizer-specific arguments through optimizer_compile_args:

compiled = optimizer.compile(
    student,
    trainset=trainset,
    valset=valset,
    strategy="p -> w",
    optimizer_compile_args={
        "p": {"max_metric_calls": 150},
    },
)

Do not pass student inside optimizer_compile_args; BetterTogether manages the current program.

Read the full file on GitHub · 107 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 · 107 lines · 32 tokens per session scan A 317c84fa86d0

Subscribe to this mod's changes

dspy-better-together is a skill published in the GitHub repository OmidZamani/dspy-skills (123 stars, last pushed 2mo ago), licensed MIT. It adds 32 tokens to every session and 775 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.