Skip to main content
Use W&B with DSPy to track and optimize your language model programs. W&B complements the Weave DSPy integration by providing:
  • Evaluation metrics tracking over time
  • W&B Tables for program signature evolution
  • Integration with DSPy optimizers like MIPROv2
For comprehensive observability when optimizing DSPy modules, enable the integration in both W&B and Weave.
NoteAs of wandb==0.21.2 and weave==0.52.5, Weave initializes automatically when used with W&B:
  • If weave is imported and then wandb.init() is called (script case)
  • If wandb.init() was called and then weave is imported later (notebook/Jupyter case)
No explicit weave.init(...) call is required.

Install and authenticate

Install the required libraries and authenticate with W&B:
  1. Install the required libraries:
  2. Set the WANDB_API_KEY environment variable and log in:
New to W&B? See our quickstart guide.

Track program optimization (experimental)

For DSPy optimizers that use dspy.Evaluate (such as MIPROv2), use the WandbDSPyCallback to log evaluation metrics over time and track program signature evolution in W&B Tables.
After running this code, you receive both a W&B Run URL and a Weave URL. W&B displays evaluation metrics over time, along with Tables that show the evolution of program signatures. The run’s Overview tab includes links to Weave traces for detailed inspection. If a run object is not passed to WandbDSPyCallback, the global run object is used.
DSPy optimization run in W&B
For comprehensive details about Weave tracing, evaluation, and optimization with DSPy, see the Weave DSPy integration guide.

Log predictions to W&B Tables

Enable detailed prediction logging to inspect individual examples during optimization. The callback creates a W&B Tables for each evaluation step, which can help you to analyze specific successes and failures.

Access prediction data

After optimization, find your prediction data in W&B:
  1. Navigate to your run’s Overview page.
  2. Look for Table panels named with a pattern like predictions_0, predictions_1, and so forth.
  3. Filter by is_correct to analyze failures.
  4. Compare tables across runs in the project workspace.
Each table includes columns for:
  • example: Input data
  • prediction: Model output
  • is_correct: Evaluation result
Learn more in the W&B Tables guide.

Save and version DSPy programs

To reproduce and version your best DSpy programs, save them as W&B Artifacts. Choose between saving the complete program or only the state.