Dspy weave
Skill lebsral/DSPy-Programming-not-prompting-LMs-skills/skills/dspy-weave
AI skills for Claude Code, Cursor, and other coding agents. Build reliable AI features with DSPy — classification, RAG, parsing, agents, and more. Just type /ai-do.
npx -y skills add lebsral/DSPy-Programming-not-prompting-LMs-skills --skill dspy-weaveAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
- 11 stars11 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Use W&B Weave for DSPy experiment tracking and observability. Use when you want to set up Weave, W&B, wandb, Weights & Biases, experiment dashboard, weave.op, or team collaboration for DSPy. Also used for weave setup, pip install weave, weave.init, wandb project, W&B experiment tracking, weave decorator, weave.op decorator, wandb dashboard, compare optimization runs, team experiment tracking.
SKILL.md
10.3 KB, ~2.6k tokens by cl100k_base, as published. Nobody here has run it
W&B Weave — Cloud Observability & Experiment Tracking for DSPy
Guide the user through setting up W&B Weave for tracing DSPy calls, tracking optimization experiments, and collaborating with team dashboards.
Before you start
Ask yourself (or the user):
- Are you already using W&B for ML experiments or do you need to create an account?
- Do you need auto-tracing of all DSPy calls, selective tracing of specific functions, or both?
- Is this for a team with shared dashboards, or a solo project?
What is W&B Weave
Weave is Weights & Biases' LLM observability and experiment tracking product. It provides cloud-hosted dashboards for tracing function calls, comparing optimization runs, and sharing results across teams.
- Cloud-hosted: Dashboards at wandb.ai
- Dual instrumentation: Auto-traces all DSPy calls out of the box; also supports
@weave.op()for custom non-DSPy functions - Team collaboration: shared projects, comments, and run comparisons
Key difference from Langtrace/Phoenix
Weave auto-instruments DSPy (like Langtrace) — once you call weave.init(), all DSPy modules, signatures, and optimizer runs are traced automatically. Weave also supports manual @weave.op() decorators for tracing non-DSPy functions. The main differentiator is the W&B experiment comparison dashboard and team collaboration features.
When to use Weave
Use Weave when:
- Your team already uses W&B for ML experiments
- You want cloud-hosted dashboards with team collaboration
- You want to track and compare optimization runs side-by-side
- You need both auto-tracing (DSPy) and selective tracing (custom functions)
Do NOT use Weave when:
- You want a free, local-only trace viewer — see
/dspy-phoenix - You need the full ML lifecycle (model registry, deployment) — see
/dspy-mlflow - You are a solo developer who does not need team features — Langtrace or Phoenix is simpler
Setup
Install
pip install weave
Initialize (auto-tracing for DSPy)
For DSPy projects, just call weave.init() — all DSPy modules, signatures, and optimizer runs are traced automatically:
import weave
import dspy
weave.init("my-dspy-project") # Creates project at wandb.ai; auto-traces all DSPy calls
dspy.configure(lm=dspy.LM("openai/gpt-4o-mini")) # or "anthropic/claude-3-5-sonnet", etc.
class QABot(dspy.Module):
def __init__(self):
self.retrieve = dspy.Retrieve(k=3)
self.answer = dspy.ChainOfThought("context, question -> answer")
def forward(self, question):
context = self.retrieve(question).passages
return self.answer(context=context, question=question)
bot = QABot()
# Every DSPy call is automatically traced — no decorators needed
answer = bot(question="How do refunds work?")
You will be prompted to log in on first run, or set WANDB_API_KEY as an environment variable.
Environment variable configuration
export WANDB_API_KEY="your-key" # From wandb.ai/settings
export WANDB_ENTITY="your-team" # Optional: team name
export WANDB_PROJECT="my-dspy-project" # Optional: project name
Tracing custom functions with @weave.op()
For non-DSPy code (custom preprocessing, business logic, API calls), use @weave.op() to add manual tracing. The decorator captures inputs, outputs, latency, and cost:
@weave.op()
def handle_question(question: str) -> str:
"""Traced by Weave — includes DSPy sub-calls automatically."""
result = bot(question=question)
return result.answer
# Weave shows the call tree: handle_question -> QABot.forward -> ChainOfThought
answer = handle_question("How do refunds work?")
Tracing multiple custom functions
@weave.op()
def fetch_user_context(user_id: str) -> dict:
return db.query("SELECT * FROM users WHERE id = ?", user_id)
@weave.op()
def handle_question(user_id: str, question: str) -> str:
ctx = fetch_user_context(user_id) # non-DSPy step, manually traced
result = bot(question=question) # DSPy step, auto-traced
return result.answer
# Weave shows the full call tree including both custom and DSPy steps
Tracking optimization experiments
Weave excels at comparing optimization runs. Wrap your optimization in @weave.op():
import weave
import dspy
from dspy.evaluate import Evaluate
weave.init("optimization-experiments")
dspy.configure(lm=dspy.LM("openai/gpt-4o-mini")) # or "anthropic/claude-sonnet-4-5-20250929", etc.
@weave.op()
def run_optimization(optimizer_name: str, model: str, auto_setting: str):
"""Run and track an optimization experiment."""
lm = dspy.LM(model)
dspy.configure(lm=lm)
program = dspy.ChainOfThought("question -> answer")
if optimizer_name == "miprov2":
optimizer = dspy.MIPROv2(metric=metric, auto=auto_setting)
elif optimizer_name == "bootstrap":
optimizer = dspy.BootstrapFewShot(metric=metric)
optimized = optimizer.compile(program, trainset=trainset)
evaluator = Evaluate(devset=devset, metric=metric, num_threads=4)
score = evaluator(optimized)
# Save the artifact
path = f"experiments/{optimizer_name}_{model}_{auto_setting}.json"
optimized.save(path)
return {
"score": score,
"optimizer": optimizer_name,
"model": model,
"auto": auto_setting,
"artifact_path": path,
}
# Run experiments — each is tracked in Weave
run_optimization("miprov2", "openai/gpt-4o-mini", "light")
run_optimization("miprov2", "openai/gpt-4o-mini", "medium")
run_optimization("bootstrap", "openai/gpt-4o-mini", "n/a")
Comparing runs in the W&B dashboard
- Go to wandb.ai and open your project
- Click on the "Traces" tab to see all tracked calls
- Compare inputs and outputs across runs
- Sort by score to find the best experiment
- Share the dashboard URL with your team
Weave vs Langtrace vs Phoenix
| Feature | W&B Weave | Langtrace | Arize Phoenix |
|---|---|---|---|
| DSPy instrumentation | Auto (weave.init()) | Auto (one line) | Auto (plugin) |
| Custom function tracing | Manual (@weave.op()) | Auto | Auto |
| Cloud dashboard | Yes (wandb.ai) | Yes (app.langtrace.ai) | Yes (Arize platform) |
| Local/self-hosted | No | Yes (Docker) | Yes (px.launch_app()) |
| Team collaboration | Yes (built-in) | Basic | Basic |
| Experiment comparison | Yes (side-by-side) | No | No |
| Built-in evals | Basic | Basic | Yes (evals module) |
| Cost | Free tier + paid plans | Free tier + paid | Free (open source) |
| Best for | Teams on W&B, experiment comparison | Lightweight auto-tracing | Local trace viewer + evals |
Decision guide
Want DSPy observability?
|
+- Team already uses W&B or need experiment comparison? -> Weave
+- Want the simplest setup with no W&B account? -> Langtrace (/dspy-langtrace)
+- Want local-only + built-in evals? -> Phoenix (/dspy-phoenix)
+- Need full ML lifecycle (registry, deploy)? -> MLflow (/dspy-mlflow)
Verifying the setup
After calling weave.init(), run a DSPy call and confirm it appears in the dashboard:
import weave
import dspy
weave.init("smoke-test")
dspy.configure(lm=dspy.LM("openai/gpt-4o-mini"))
predict = dspy.Predict("question -> answer")
result = predict(question="What is 2+2?")
print(f"Check your project at https://wandb.ai — look for the Predict call in Traces")
If the call does not appear: check WANDB_API_KEY is set, confirm weave.init() was called before any DSPy calls, and verify network access to wandb.ai.
Gotchas
- Claude puts
@weave.op()on the DSPy module class instead of the calling function. Weave decorators trace regular functions, not DSPy module classes. Decorate the function that calls the module, not the module itself.@weave.op()goes onhandle_question(), not onQABot. - Claude calls
weave.init()inside a function instead of at module level.weave.init()must run once at startup, before any@weave.op()decorated functions are called. Placing it inside a request handler creates a new project per call and fragments your traces. - Claude forgets to set
WANDB_API_KEYin deployment environments. Local development prompts for login interactively, but production (Docker, CI, serverless) needs the environment variable explicitly set. Always includeWANDB_API_KEYin environment configuration for non-local setups. - Claude adds unnecessary
@weave.op()to every DSPy module. DSPy calls are auto-traced onceweave.init()is called — no decorators needed ondspy.Modulesubclasses. Reserve@weave.op()for non-DSPy custom functions (preprocessing, database calls, business logic) that you also want in the trace tree. - Claude nests
@weave.op()and DSPy decorators incorrectly. If combining with other decorators,@weave.op()should be the outermost decorator so it captures the full function execution including any inner decorator behavior.
Additional resources
- W&B Weave docs
- DSPy integration guide
- Weave Python SDK reference
- W&B dashboard
- For API details, see reference.md
- For worked examples, see examples.md
Cross-references
Install any skill:
npx skills add lebsral/DSPy-Programming-not-prompting-LMs-skills --skill <name>
- Langtrace (auto-instrumentation, no W&B account needed) —
/dspy-langtrace - Arize Phoenix (open-source with evals) —
/dspy-phoenix - MLflow (full ML lifecycle) —
/dspy-mlflow - Aggregate monitoring —
/ai-monitoring - Experiment tracking patterns (JSONL-based, lightweight) —
/ai-tracking-experiments - Install
/ai-doif 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-do