Define a Model Signature and Schema
Declare expected inputs and outputs explicitly.
Define a Model Signature and Schema is a free MLOps Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the MLOps Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What Goes In, What Comes Out
A model's signature declares exactly what inputs it expects and what outputs it returns. It is the model's contract. 📜
Why Signatures Matter
With a clear schema, callers know which columns and types to send. Bad input gets caught early instead of crashing at predict time.
Inputs and Outputs
A signature has two parts: the input schema describing each feature, and the output schema describing the prediction shape.
Column vs Tensor Schemas
Tabular models use a column schema of named, typed fields. Image or text models often use a tensor schema of shapes and dtypes.
Infer It Automatically
The easiest path is infer_signature: hand it sample inputs and outputs and MLflow figures out the schema for you.
from mlflow.models import infer_signature
sig = infer_signature(X, model.predict(X))Attach It When Logging
Pass the inferred signature into log_model so it gets saved right inside the model's MLmodel file.
mlflow.sklearn.log_model(model, name='m', signature=sig)Add an Input Example
Logging an input_example too gives teammates a copy-paste sample of valid input and helps tools build correct requests.
mlflow.sklearn.log_model(model, name='m',
input_example=X[:1])Enforcement at Serving
When you serve the model, MLflow checks each request against the schema and rejects inputs with the wrong type or missing fields. 🛡️
Safe Type Coercion
MLflow can quietly upcast safe types, like int to long, but it blocks lossy changes so your model never sees corrupted data.
Optional and Extra Columns
You can mark fields optional, and extra unexpected columns are dropped, so minor input changes do not break serving.
A Living Document
The signature doubles as docs: open the MLmodel file and you instantly see the model's full input and output contract.
Quick Check
Final check on model signatures and schemas.
Recap
A signature is your model's input and output contract: infer it, log it with an example, and let MLflow enforce it at serving. 🎉
Frequently asked questions
Is the “Define a Model Signature and Schema” lesson free?
Yes — the full text of “Define a Model Signature and Schema” is free to read here on the web, and the MLOps Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the MLOps Academy course, upgrade to CoddyKit PRO.
What will I learn in “Define a Model Signature and Schema”?
Declare expected inputs and outputs explicitly. You practise MLOps Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start MLOps Academy?
No prior experience is required. MLOps Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Define a Model Signature and Schema” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this MLOps Academy lesson?
Yes. Every MLOps Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Serialize with Pickle and Joblib
- The MLflow Model Flavor
- Export to ONNX for Portability
- Define a Model Signature and Schema