Skip to main content
Reflex ships with a callback system that lets you stream run data to experiment tracking platforms. Callbacks are optional — they never affect core optimization behavior, and a broken callback will never crash a run.

Usage

Pass a callbacks list to .run():
Multiple callbacks can be composed freely:

MLflow

MLflowCallback logs the full run to an MLflow experiment using MLflow’s standard tracking API. No server required — by default it writes to a local ./mlruns directory that you can open with mlflow ui. Install:
CLI:
Python API:
With options:

What gets logged

Viewing results

Navigate to your results in three steps:
  1. Experiments (left sidebar) → click the experiment name (e.g. security-incidents)
  2. Click Evaluation Runs — the table lists every reflex run with its baseline and best score
  3. Click a run name to open it, then:
    • Overview — run params (strategy, reasoning_model, etc.) and summary metrics (best_score_train, baseline_score, final_score_test, improvement)
    • Model metrics — score trajectory chart, one point per iteration
    • Artifacts → iterations.json — interactive table showing the prompt and reasoning used at each iteration alongside its score
    • Artifacts → prompts/best_prompt_*.txt with the final winning prompt

Writing a custom callback

Implement any subset of the three lifecycle methods:
You only need to implement the methods you care about. Callbacks that are missing a method are skipped silently — there is no base class to inherit from. The lifecycle order is: on_run_starton_baselineon_iteration (×N) → on_finalon_run_end.

Weights & Biases

WandbCallback logs the full run to a W&B project using the standard wandb Python SDK. Install:
CLI:
Python API:
With options:
Testing without a W&B account: Use mode="offline" to write runs locally without any network access. Run wandb sync ./wandb/offline-run-* later to push them.

What gets logged

The Charts tab shows score_train, score_val, and score_test (baseline + final) as separate series, giving you a clear view of train vs. validation vs. held-out test performance across the run. Summary fields appear in the run Overview table, making it easy to compare runs side by side.

Using both together

MLflow and W&B can run simultaneously — pass both in the callbacks list: