Sub topic 16
Governance, lineage and compliance
This chapter assumes you can train and evaluate a supervised model, use Git, and have seen the earlier chapters on experiment tracking, the model registry and production monitoring. Governance builds on those records. It decides who may change them, what must be kept, and how you prove what happened later.
What governance means in MLOps
Governance is the set of rules, approvals and records that make a model's behavior accountable. It answers questions that people outside the ML team ask:
- Which data trained the model that made this decision?
- Who approved its release, and against which criteria?
- Can we reproduce the model, or explain why we cannot?
- What did the model do in production during a given week?
Lineage is the technical core of governance. It is the recorded chain linking each artifact to the artifacts it was derived from. Compliance is the demonstration that your practices meet an external requirement, such as a regulation, an audit standard or a customer contract. Lineage supplies the evidence, and governance supplies the process around it.
What lineage records
Lineage covers more than the model file. For each model version, record:
| Link | What to store | Where it usually comes from |
|---|---|---|
| Data | Dataset version or content hash, source, collection date | Data versioning tool, validation reports |
| Code | Git commit, dirty-tree flag | Version control |
| Environment | Library versions, container image digest | Lock file, image registry |
| Configuration | Hyperparameters, random seeds | Experiment tracker |
| Evaluation | Metrics, test set version, release decision | Evaluation step, CI/CD logs |
| Deployment | Which version served which traffic, and when | Registry, serving platform |
Each row should reference the others by an identifier that cannot silently change. A name like train_final.csv is not enough because the file under it can be overwritten. A content hash or an immutable version ID is.
Lineage must work in both directions. Forward tracing answers "which models used this dataset?", which you need when a data source turns out to be faulty or when a person withdraws consent. Backward tracing answers "what produced this prediction?", which you need for incident review and for explaining a disputed decision.
Capturing a lineage record
Most trackers and registries store parts of this record. A small, explicit record that you write alongside every trained model keeps the links visible and tool-independent. The following script hashes a dataset file and builds a record for it.
import hashlib
import json
import tempfile
from datetime import datetime, timezone
from pathlib import Path
def sha256_file(path):
digest = hashlib.sha256()
with open(path, "rb") as f:
for chunk in iter(lambda: f.read(1 << 20), b""):
digest.update(chunk)
return digest.hexdigest()
def build_lineage_record(data_path, git_commit, params, metrics, approved_by):
return {
"created_at": datetime.now(timezone.utc).isoformat(),
"dataset": {"path": str(data_path), "sha256": sha256_file(data_path)},
"code": {"git_commit": git_commit},
"params": params,
"metrics": metrics,
"approval": {"approved_by": approved_by},
}
with tempfile.TemporaryDirectory() as tmp:
data_file = Path(tmp) / "train.csv"
data_file.write_text("x,y\n1,0\n2,1\n3,1\n")
record = build_lineage_record(
data_path=data_file,
git_commit="3f2a9c1",
params={"C": 1.0, "seed": 42},
metrics={"accuracy": 0.94},
approved_by="release-bot",
)
print(json.dumps(record, indent=2))If someone edits train.csv and retrains, the hash changes, so two models trained on different data can no longer be mistaken for each other. In a real pipeline, take the commit from git rev-parse HEAD, and fail the run if the working tree has uncommitted changes. A commit hash only identifies the code if the code matches the commit.
Controls that make the records trustworthy
Records are only useful if they are complete and hard to falsify. Common controls:
- Automatic capture. Pipelines write lineage as a side effect of running. Manual documentation drifts from reality within weeks.
- Immutable versions. A registered model version, once created, is never overwritten. A fix becomes a new version.
- Access control. Separate the right to train, to promote and to deploy. Promotion to production should need a person or an automated gate that is not the author of the change.
- Approval gates. The release criteria from the evaluation chapter, such as an accuracy floor and a no-regression check, become recorded decisions. Store who or what approved, and which numbers they saw.
- Audit logs. Registry transitions (staging to production, rollbacks, deletions) are appended to a log that ordinary users cannot edit.
- Retention rules. Decide how long to keep datasets, models and prediction logs. Keep them long enough for audits and short enough to meet privacy rules.
Documentation: model cards and data sheets
Lineage is machine-readable evidence. People also need a readable summary. A model card is a short document attached to a model version that states:
- the intended use and known out-of-scope uses
- the training data, and its known gaps
- evaluation results, ideally broken down by relevant subgroups
- known limitations and failure modes
- monitoring plan and owner
A data sheet does the same for a dataset: how it was collected, what it contains, and what consent or license applies. Generate as much of both as possible from the lineage record, and review the rest by hand. A card that is written once and never updated is a compliance risk, because it describes a model that no longer exists.
Compliance in practice
Requirements vary by industry and region, so check with your legal or compliance team instead of inferring them from a tutorial. Several themes recur:
- Privacy and data protection. Personal data in training sets and prediction logs may require a legal basis, minimization, and the ability to delete it. Forward lineage tells you which models are affected by a deletion request. Whether a model must then be retrained is a legal and technical judgment.
- Explainability and contestability. Some decisions, such as credit or hiring, may need an explanation or human review. Prediction logs that store the model version and input features make that possible.
- Risk classification. Newer regulations classify AI systems by risk and require documentation, human oversight and monitoring for higher-risk ones.
- Fairness. Evaluation by subgroup, repeated in monitoring, shows whether performance gaps appear after release.
- Security. Protect training data, model artifacts and registries against tampering. A poisoned dataset or replaced model file is a lineage failure as well as a security one.
Common failure modes
- Lineage gaps. The model is registered, but the notebook that produced it used a local CSV. Fix this by letting only the pipeline register models.
- Logging too little. Predictions are served without the model version, so incidents cannot be traced.
- Logging too much. Raw personal data is kept in prediction logs forever. Log identifiers and features you need, and apply retention limits.
- Approval theater. The approver clicks through without seeing the metrics. Show the evidence on the approval screen and record it.
- Stale documentation. Model cards are not regenerated after retraining.
Exercise
A customer asks why their loan application was declined three months ago. Which lineage links do you need to answer, and what would make it impossible?
Show answer
You need the prediction log entry (with the model version and input features), the registry record for that model version, and from it the dataset hash, Git commit, configuration and evaluation report. It becomes impossible if predictions were logged without the model version, if the registry version was overwritten or deleted, if the dataset was stored under a mutable name with no hash, or if retention rules removed the logs before three months passed.
Exercise
Why does the lineage script above hash the file contents instead of storing only the file name?
Show answer
A file name can point to different contents over time, so it cannot prove which data trained the model. A SHA-256 hash changes whenever the contents change, so it identifies the exact data and exposes silent edits.