Getting started¶
Install¶
Pulls scikit-learn, fairlearn and shap, which the fairness checks and most metrics need.
Python 3.9 – 3.13.
Gate a model¶
from bdp_model_gate import ModelGate, StructuredGateContext
context = StructuredGateContext(
model=my_model,
X=X_val,
y_true=y_val,
y_pred=y_pred, # positive-class probability, for binary
protected_df=protected_val, # optional — enables fairness
model_card=my_model_card, # optional — enables compliance
task="binary",
)
report = ModelGate().run(context)
print(report.summary())
report.to_json("gate_report.json")
Gate status: NEEDS_REVIEW (2741ms, binary)
roc_auc: 0.8637
performance: 0 flag(s)
compliance: 0 flag(s)
security: 0 flag(s)
fairness: 4 flag(s)
Only model (or a predict_fn), X, y_true and y_pred are required.
Every other field is optional, and omitting one makes the checks that need it
report NOT_APPLICABLE instead of failing. See
Concepts.
Read the verdict¶
if report.gate_status == "BLOCKED":
raise SystemExit("Model failed governance — see gate_report.json")
for flag in report.flags:
print(flag.check_name, flag.detail)
| Status | Meaning | Your pipeline should |
|---|---|---|
| PASS | nothing flagged | deploy automatically |
| NEEDS_REVIEW | only non-blocking flags | pause for human sign-off |
| BLOCKED | a blocking check failed | hard-fail the build |
From the command line¶
bdp-model-gate \
--model model.joblib \
--data validation.csv \
--target-col label \
--protected protected.csv \
--model-card model_card.json \
--task binary \
--metric roc_auc --min-score 0.80 \
--output gate_report.json
Exit codes are 0, 2 and 1 for the three statuses, so a pipeline can tell
deploy from ask a human. Full options in the CLI reference.
Next¶
- Concepts — how the pieces fit
- Your task: binary · multiclass · regression
- Examples — five runnable notebooks