Stop weak models with a quality gate

DevOps, Hands On15 minutesFreeSteps checked 23 November 2026By Cloud Hands On

In this task you'll make a training run fail, and stop the pipeline, when the model isn't good enough.

A quality gate is a check that must pass before a model moves on. In train.py, --min-auc sets the bar: below it the run is tagged gate=failed, nothing is saved or registered, and the script exits with code 1. Pipelines treat any non-zero exit code as a failure, so later stages never run.

Set the bar from evidence: above the baseline, and close to what the current model achieves. A fixed number is a start; comparing with the model already in production (the promotion task) is better. Gates can also check fairness across groups, prediction speed and model size.

Example. Larkfield Group's demand forecast was retrained every week by a script. One week a broken export halved the data and the new model was much worse, but it went live anyway. A gate at the old model's error level would have stopped it and paged the team instead.

Before you start

You need: Python 3.10 or newer, and about 500 MB of disk for MLflow and scikit-learn. No cloud account. Time: 15 minutes.

Where to look

  1. mlops folder
  2. train.py --min-auc
  3. MLflow UI
  4. gate tag

Steps

  1. Run python train.py --min-auc 0.9. It prints GATE FAILED and stops.AUC about 0.78 is under 0.9.
  2. Check the exit code: echo $? in bash, or $LASTEXITCODE in PowerShell. It's 1.A pipeline step that returns 1 stops the pipeline.
  3. Run python train.py --min-auc 0.7. It passes and saves the model, and the exit code is 0.
  4. In the MLflow UI, add the gate tag as a column: one run failed, one passed.

Commands

# The gate inside train.py
if m["auc"] < a.min_auc:
    mlflow.set_tag("gate", "failed")
    print(f"GATE FAILED: auc {m['auc']:.4f} is under {a.min_auc}. Nothing registered.")
    sys.exit(1)

# Try it
python train.py --min-auc 0.9
echo $?               # bash: 1 means the gate failed
$LASTEXITCODE         # PowerShell
python train.py --min-auc 0.7

Watch out for

Cost
Free.
Security
Keep the threshold in reviewed code or pipeline settings, not something anyone can change at run time without a trace.
Common mistakes
A gate below the baseline, and a gate that logs a warning but still exits 0.

Clean up

Keep the mlops folder for the next tasks in this section; delete it (and its .venv) at the end.

Words to know

Quality gate
A check a model must pass before it moves to the next stage.
Exit code
A program's result number: 0 means success, anything else means failure.
Threshold
The score a model must reach to pass.
Fail closed
When a check fails, stop rather than carry on.

Tick off each step and track your progress in the guide.

Open this task in DevOps, Hands On

Keep going