What are model signatures and input examples in MLflow, and why do they matter operationally?
Quick Answer
A signature is the model's typed I/O schema (column names, dtypes, tensor shapes) stored with the artifact; an input example is a concrete sample payload. They turn 'model file' into 'contract': serving validates requests against the schema, batch pipelines catch drift in upstream feature columns at load time instead of scoring garbage, and every consumer can see what the model expects without reading training code.
Detailed Answer
Signatures are inferred (infer_signature(X, y)) or declared at log time and stored in MLmodel metadata. Operational value: (1) request validation — MLflow serving rejects payloads with missing/mistyped columns with a clear error, instead of the model silently mis-scoring reordered or renamed features; (2) integration contract — downstream teams generate clients and feature pipelines against the schema, and schema diffs between model versions become reviewable artifacts in promotion PRs; (3) drift tripwire — when an upstream table renames a column, load-time/score-time validation fails loudly at deploy rather than quietly degrading predictions for weeks; (4) the input example doubles as a smoke test — CI loads every newly registered version and scores the example before any alias moves. Since MLflow 2.x-3.x, signature enforcement got stricter by default, and models logged without signatures generate warnings — treat a missing signature as a registration failure in your CI gates. The classic war story this prevents: feature order changing in a SELECT * pipeline and the model scoring shuffled features 'successfully' for a month.
Code Example
sig = infer_signature(X_train.head(50), model.predict(X_train.head(50)))
mlflow.sklearn.log_model(model, 'model', signature=sig,
input_example=X_train.head(3),
registered_model_name='churn')
# CI gate on every new version
mv = client.get_model_version('churn', v)
assert mlflow.models.get_model_info(mv.source).signature is not NoneInterview Tip
Tell the shuffled-features story: a model scoring reordered columns 'successfully' is the silent failure signatures exist to prevent — it makes the abstract 'schema contract' concrete.