skills/dspy-vizpy/SKILL.md
Use VizPy as a drop-in prompt optimizer for DSPy. Use when you want to try VizPy, vizops, ContraPromptOptimizer, PromptGradOptimizer, a commercial alternative to GEPA, a third-party prompt optimizer, or a different optimization backend. Also used for vizpy optimizer, vizpy vs GEPA, vizpy vs MIPROv2, commercial prompt optimization, ContraPrompt for classification, PromptGrad for generation, vizpy API key, pip install vizpy, vizpy free tier.
npx skillsauth add lebsral/dspy-programming-not-prompting-lms-skills dspy-vizpyInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Guide the user through integrating VizPy as a drop-in prompt optimizer alongside or instead of DSPy's native optimizers (GEPA, MIPROv2).
Before recommending VizPy, clarify:
VizPy is a commercial SaaS prompt optimization service (vizpy.vizops.ai) that provides two optimizers for DSPy programs:
Both optimize the instruction string only — the same limitation as dspy.GEPA. They do NOT optimize few-shot demos, Pydantic field descriptions, or model weights.
| Tier | Optimization runs/month | Cost | |------|------------------------|------| | Free | 10 | $0 | | Pro | Unlimited | $20/mo |
Use VizPy when:
Do NOT use VizPy when:
dspy.BootstrapFewShot or dspy.MIPROv2/dspy-gepadspy.BootstrapFinetunedspy.GEPA or dspy.MIPROv2pip install vizpy
Set your API key:
import vizpy
vizpy.api_key = "your-vizpy-api-key" # from vizpy.vizops.ai/dashboard
Or via environment variable:
export VIZPY_API_KEY="your-vizpy-api-key"
Best for tasks with a fixed set of output categories.
import dspy
import vizpy
dspy.configure(lm=dspy.LM("openai/gpt-4o-mini")) # or "anthropic/claude-sonnet-4-5-20250929", etc.
# 1. Define your classifier
classify = dspy.ChainOfThought("text -> label")
# 2. Prepare training data
trainset = [
dspy.Example(text="Great product!", label="positive").with_inputs("text"),
dspy.Example(text="Terrible service.", label="negative").with_inputs("text"),
# ... 50+ examples recommended
]
# 3. Define a metric
def metric(example, prediction, trace=None):
return prediction.label.lower() == example.label.lower()
# 4. Optimize with VizPy
optimizer = vizpy.ContraPromptOptimizer(metric=metric)
optimized = optimizer.compile(classify, trainset=trainset)
# 5. Use the optimized program
result = optimized(text="This exceeded my expectations!")
print(result.label)
# 6. Save
optimized.save("vizpy_optimized_classifier.json")
ContraPromptOptimizer uses contrastive examples — it identifies cases where the current instruction fails and generates instruction candidates that distinguish between confusing categories. This is particularly effective when categories are semantically close (e.g., "billing" vs "account" tickets).
Best for open-ended generation tasks where output quality is on a spectrum.
import dspy
import vizpy
dspy.configure(lm=dspy.LM("openai/gpt-4o-mini")) # or "anthropic/claude-sonnet-4-5-20250929", etc.
# 1. Define your generator
summarize = dspy.ChainOfThought("article -> summary")
# 2. Prepare training data
trainset = [
dspy.Example(
article="Long article text here...",
summary="Expected summary."
).with_inputs("article"),
# ... 50+ examples
]
# 3. Define a metric (can be AI-as-judge)
class AssessQuality(dspy.Signature):
"""Assess if the summary captures key points accurately."""
article: str = dspy.InputField()
gold_summary: str = dspy.InputField()
predicted_summary: str = dspy.InputField()
score: float = dspy.OutputField(desc="0.0 to 1.0")
def metric(example, prediction, trace=None):
judge = dspy.Predict(AssessQuality)
result = judge(
article=example.article,
gold_summary=example.summary,
predicted_summary=prediction.summary,
)
return result.score
# 4. Optimize with VizPy
optimizer = vizpy.PromptGradOptimizer(metric=metric)
optimized = optimizer.compile(summarize, trainset=trainset)
# 5. Use
result = optimized(article="New article text...")
print(result.summary)
PromptGradOptimizer uses gradient-inspired optimization — it estimates how instruction changes affect output quality scores and iteratively adjusts the instruction in the direction that improves the metric. This works well for generation tasks where quality is continuous rather than binary.
| Aspect | VizPy ContraPrompt | VizPy PromptGrad | dspy.GEPA | dspy.MIPROv2 | |--------|-------------------|-----------------|-----------|-------------| | Best for | Classification | Generation | Both | Both | | What it tunes | Instructions only | Instructions only | Instructions only | Instructions + demos | | Data needed | ~50 examples | ~50 examples | ~50 examples | ~200 examples | | Expected improvement | 5-18% | 5-18% | 5-15% | 15-35% | | Cost | Free tier (10 runs) | Free tier (10 runs) | ~$0.50 (LM calls) | ~$5-15 (LM calls) | | Open source | No (SaaS) | No (SaaS) | Yes | Yes | | Feedback-driven | Contrastive examples | Gradient-inspired | Textual feedback | Scalar scores | | Pydantic field desc | No | No | No | No |
Want instruction-only optimization?
|
+- Classification task?
| +- Want open-source? -> dspy.GEPA
| +- Want to try commercial? -> vizpy.ContraPromptOptimizer
|
+- Generation task?
| +- Want open-source? -> dspy.GEPA
| +- Want to try commercial? -> vizpy.PromptGradOptimizer
|
+- Want instructions AND demos? -> dspy.MIPROv2
VizPy optimizers are drop-in replacements for GEPA — same .compile() interface:
# With GEPA
optimizer = dspy.GEPA(metric=metric, auto="light")
optimized = optimizer.compile(program, trainset=trainset)
# With VizPy ContraPrompt (swap one line)
optimizer = vizpy.ContraPromptOptimizer(metric=metric)
optimized = optimizer.compile(program, trainset=trainset)
The optimized program is a standard DSPy program either way — save(), load(), and Evaluate all work identically.
Instruction-only optimization — VizPy does NOT optimize Pydantic Field(description=...), InputField(desc=...), or OutputField(desc=...). Same limitation as GEPA. See /dspy-gepa for a workaround (flatten field descriptions into the instruction).
SaaS dependency — your training data is sent to VizPy's servers for optimization. Check your data privacy requirements.
No offline mode — requires internet access and a valid API key.
Free tier limits — 10 optimization runs per month. Each .compile() call counts as one run.
After running .compile(), compare baseline vs optimized:
from dspy.evaluate import Evaluate
evaluator = Evaluate(devset=devset, metric=metric, num_threads=4)
# Baseline
baseline_score = evaluator(program)
print(f"Baseline: {baseline_score}")
# After VizPy optimization
optimized_score = evaluator(optimized)
print(f"Optimized: {optimized_score}")
print(f"Improvement: {optimized_score - baseline_score:.1f}%")
If the optimized score is not higher, the instruction change may not help this task. Try a different optimizer (GEPA, MIPROv2) or add few-shot demos with MIPROv2.
dspy.BootstrapFewShot or dspy.MIPROv2 first, then layer VizPy on top for instruction tuning.dspy.Evaluate before and after.vizpy.api_key or VIZPY_API_KEY. VizPy is SaaS and requires authentication. Without the API key set, .compile() fails with a confusing auth error. Set it before any optimizer calls.Install any skill:
npx skills add lebsral/DSPy-Programming-not-prompting-LMs-skills --skill <name>
/dspy-gepa/dspy-miprov2/ai-improving-accuracy/dspy-evaluate/ai-do if you do not have it — it routes any AI problem to the right skill and is the fastest way to work: npx skills add lebsral/DSPy-Programming-not-prompting-LMs-skills --skill ai-dotools
See what is happening during optimizer.compile() instead of waiting blind. Use when you want to watch optimization progress, see scores as they come in, know if your optimizer is working, check if optimization is stuck, understand why optimization is taking too long, get live progress during compile, monitor convergence, detect overfitting during optimization, interpret optimization results, or pick the right tool for watching optimization. Also used for optimizer progress bar, is my optimizer doing anything, optimization seems stuck, how long will optimization take, watch GEPA run, watch MIPROv2 run, live optimization dashboard, optimizer not improving, scores not going up, optimization taking forever, see what optimizer is doing, debug slow optimization, optimization visibility, optimizer metrics, track compile progress, optimization observability.
testing
Use when you want the highest-quality prompt optimization DSPy offers — jointly optimizes instructions and few-shot demos, with auto=light/medium/heavy presets. Common scenarios - you want the best possible accuracy from prompt optimization, jointly tuning instructions and few-shot demonstrations, using auto presets for different compute budgets, or when COPRO or BootstrapFewShot alone are not reaching your accuracy target. Related - ai-improving-accuracy, dspy-copro, dspy-bootstrap-few-shot. Also used for dspy.MIPROv2, best DSPy optimizer, highest quality optimization, auto=light medium heavy, joint instruction and demo optimization, most powerful prompt optimizer, MIPROv2 vs COPRO vs BootstrapFewShot, which optimizer should I use, state of the art prompt optimization, when to use MIPROv2, optimize both instructions and examples, heavy optimization for production, best optimizer for accuracy.
testing
Use LangWatch for DSPy auto-tracing and real-time optimizer progress. Use when you want to set up LangWatch, langwatch.dspy.init, auto-tracing DSPy, real-time optimization dashboard, optimizer progress tracking, app.langwatch.ai, or DSPy optimizer dashboard. Also used for langwatch setup, pip install langwatch, langwatch trace, optimizer progress, real-time optimization, watch optimizer run, LangWatch self-hosted, langwatch docker, langwatch vs langtrace, langwatch autotrack_dspy.
data-ai
Use when you want to optimize instructions without few-shot examples — a lightweight alternative to COPRO when you do not have or do not want to use demonstrations. Common scenarios - optimizing instructions when you do not have or do not want to use few-shot demonstrations, lightweight instruction search as a first step, tasks where examples in the prompt confuse the model, or when you want fast instruction optimization without the cost of COPRO. Related - ai-improving-accuracy, dspy-copro, dspy-miprov2. Also used for dspy.GEPA, instruction optimization without demos, lightweight prompt optimization, optimize instructions only, no few-shot examples needed, GEPA vs COPRO, quick instruction search, when demonstrations hurt performance, zero-shot optimization, instruction-only optimizer, simplest instruction tuner, fast prompt optimization, skip few-shot and just tune instructions, optimize Pydantic field descriptions, GEPA structured output, GEPA does not optimize field desc.