skills/dspy-mlflow/SKILL.md
Use MLflow for DSPy tracing, experiment tracking, and model registry. Use when you want to set up MLflow, mlflow.dspy.autolog, MLflow Tracing, MLflow experiment tracking, MLflow model registry, or full ML lifecycle management. Also used for mlflow setup, pip install mlflow, mlflow.set_experiment, mlflow UI, mlflow model versioning, mlflow OpenTelemetry, mlflow vs wandb, mlflow tracing DSPy, register DSPy model.
npx skillsauth add lebsral/dspy-programming-not-prompting-lms-skills dspy-mlflowInstall 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 using MLflow for DSPy auto-tracing, experiment tracking, model registry, and production deployment.
MLflow is an open-source platform for the complete ML lifecycle. Its DSPy integration provides:
mlflow.dspy.autolog() traces all DSPy calls via OpenTelemetryMLflow covers the full ML lifecycle — tracing, experiment tracking, model versioning, AND deployment. The others focus primarily on observability. If you need a model registry or artifact management alongside tracing, MLflow is the right choice.
Use MLflow when:
Do NOT use MLflow when:
/dspy-langtrace/dspy-phoenix/dspy-weavepip install mlflow
import mlflow
mlflow.dspy.autolog() # auto-traces all DSPy calls
import dspy
dspy.configure(lm=dspy.LM("openai/gpt-4o-mini")) # or "anthropic/claude-sonnet-4-5-20250929", etc.
program = dspy.ChainOfThought("question -> answer")
result = program(question="What is DSPy?")
# View traces in MLflow UI: mlflow ui
mlflow ui # Opens at http://localhost:5000
The UI shows:
One line traces everything DSPy does:
import mlflow
mlflow.dspy.autolog()
import dspy
dspy.configure(lm=dspy.LM("openai/gpt-4o-mini")) # or "anthropic/claude-sonnet-4-5-20250929", etc.
class RAGPipeline(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)
pipeline = RAGPipeline()
result = pipeline(question="How do refunds work?")
# MLflow captures:
# - RAGPipeline call (input/output, latency)
# - Retrieve call (query, passages)
# - ChainOfThought LM call (prompt, response, token counts)
| Component | Details | |-----------|---------| | LM calls | Full prompt, response, token counts, latency | | Retrievals | Query, passages, scores | | Module steps | Input/output per module in the pipeline | | Cost | Token-based cost estimates | | Errors | Stack traces for failed calls |
Track optimization runs with parameters, metrics, and artifacts:
import mlflow
import dspy
from dspy.evaluate import Evaluate
mlflow.dspy.autolog()
mlflow.set_experiment("dspy-optimization")
dspy.configure(lm=dspy.LM("openai/gpt-4o-mini")) # or "anthropic/claude-sonnet-4-5-20250929", etc.
trainset = [...] # your training examples
devset = [...] # your dev examples
def metric(example, prediction, trace=None):
return prediction.answer.strip().lower() == example.answer.strip().lower()
# Each run is a separate experiment
with mlflow.start_run(run_name="mipro-light"):
mlflow.log_param("optimizer", "MIPROv2")
mlflow.log_param("auto", "light")
mlflow.log_param("model", "openai/gpt-4o-mini")
mlflow.log_param("trainset_size", len(trainset))
program = dspy.ChainOfThought("question -> answer")
optimizer = dspy.MIPROv2(metric=metric, auto="light")
optimized = optimizer.compile(program, trainset=trainset)
evaluator = Evaluate(devset=devset, metric=metric, num_threads=4)
score = evaluator(optimized)
mlflow.log_metric("dev_score", score)
# Save the optimized program as an artifact
optimized.save("optimized_program.json")
mlflow.log_artifact("optimized_program.json")
mlflow ui and open http://localhost:5000dev_score to find the best runVersion and manage optimized DSPy programs:
import mlflow
# Register the best run's model
with mlflow.start_run(run_name="best-model"):
program = dspy.ChainOfThought("question -> answer")
optimizer = dspy.MIPROv2(metric=metric, auto="medium")
optimized = optimizer.compile(program, trainset=trainset)
# Log as an MLflow model
mlflow.dspy.log_model(optimized, "qa-model")
# Register in the model registry
mlflow.register_model(
f"runs:/{mlflow.active_run().info.run_id}/qa-model",
"production-qa"
)
import mlflow
# Load the latest version
model = mlflow.dspy.load_model("models:/production-qa/latest")
result = model(question="What is your return policy?")
# Load a specific version
model_v2 = mlflow.dspy.load_model("models:/production-qa/2")
Use aliases (like champion) to tag which version serves production traffic. Reassign the alias to promote a new version — no downtime, instant rollback:
from mlflow import MlflowClient
client = MlflowClient()
# Set the champion alias to version 2
client.set_registered_model_alias("production-qa", "champion", version=2)
# Load by alias in production code
model = mlflow.dspy.load_model("models:/production-qa@champion")
The MLflow UI at http://localhost:5000 provides:
| Feature | MLflow | Langtrace | W&B Weave |
|---------|--------|-----------|-----------|
| Auto-tracing | Yes (autolog()) | Yes (one line) | No (manual @weave.op()) |
| Experiment tracking | Yes (built-in) | No | Yes (via decorators) |
| Model registry | Yes | No | No |
| Local UI | Yes (mlflow ui) | Yes (Docker) | No (cloud only) |
| Cloud option | Yes (Databricks) | Yes (app.langtrace.ai) | Yes (wandb.ai) |
| Open source | Yes | Yes | No |
| Team collaboration | Basic | Basic | Yes (built-in) |
| Best for | Full ML lifecycle | DSPy-first auto-tracing | Teams on W&B |
What do you need?
|
+- Just tracing (easiest setup)? -> Langtrace (/dspy-langtrace)
+- Tracing + evals (local)? -> Phoenix (/dspy-phoenix)
+- Tracing + experiment tracking (cloud)? -> Weave (/dspy-weave)
+- Tracing + experiments + model registry? -> MLflow
+- Already on Databricks? -> MLflow (native integration)
transition_model_version_stage() which is deprecated. MLflow replaced model stages with model aliases. Use client.set_registered_model_alias("model-name", "champion", version=N) and load with mlflow.dspy.load_model("models:/model-name@champion").mlflow.dspy.autolog() after importing and configuring DSPy. Autolog must be called before any DSPy code executes — it patches DSPy modules at import time. Call mlflow.dspy.autolog() as the first line after import mlflow.mlflow.set_experiment() before start_run(). Without it, all runs go to the "Default" experiment, making it impossible to compare related optimization runs. Always set an experiment name before starting runs.mlflow.log_param("model", "openai/gpt-4o-mini") inside the run so you can filter and compare across models later.Install any skill:
npx skills add lebsral/DSPy-Programming-not-prompting-LMs-skills --skill <name>
/dspy-langtrace/dspy-phoenix/dspy-weave/ai-serving-apis/ai-tracking-experiments/ai-monitoring/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.