Signatures and environments
Quick answer
A model signature describes expected model inputs and outputs, including data types and shapes or named columns. An environment record specifies the interpreter and package dependencies needed to reproduce the model behavior. Examples use standard-library Python unless marked native MLflow, which is syntax-checked only. ByteMind execution is unverified.
Infer a synthetic MLflow signature (native, pending)
import mlflowimport numpy as npfrom mlflow.models import infer_signaturex=np.array([[1.,2.],[3.,4.]],dtype=np.float64)y=x.sum(axis=1)sig=infer_signature(x,y)print(sig.inputs is not None and sig.outputs is not None)Expected output (NOT RUN): True. Expected presence of both schemas; native execution pending.
How it works
A signature catches interface mismatches, but cannot ensure correct units, feature semantics, safe inputs, or accuracy. Pair it with a small synthetic input example and separate range and missingness checks. Infer a signature from representative input and model output; a single example may not express optional fields or all accepted types. In MLflow 3.x, flavor-specific log_model can record signatures and dependency metadata; check exact version and compatibility before using it. Record the Python build, package versions, device, seeds, code and data hashes, and dependency lock digest. A list of top-level packages is not a full lock; transitive dependencies and platform builds matter. An environment file is not a trusted installer instruction. Review it before installation, avoid untrusted model deserialization, and never run remote model code automatically.
Semantic validation beyond shape
def valid(row): return len(row)==2 and all(type(v) in (int,float) for v in row) and 0<=row[0]<=100print(valid([40,3]),valid([400,3]))Expected output (locally tested): True False. Identical shapes do not imply acceptable units or ranges.
Common mistakes
Do not confuse signature validation with semantic validation, assume package versions alone guarantee bitwise reproducibility, or log real sensitive input examples.
Practice and next steps
Write a proposed contract for two numeric input features with explicit units and one numeric prediction. Identify one schema-valid but semantically invalid input.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Signatures and environments — knowledge check
Apply signatures and environments to small examples and debugging scenarios.
What does a signature describe?
Why include a synthetic input example?
What can pass a numeric signature but still be invalid?
Is a list of two package versions a full lock?
Should unknown serialized models be loaded automatically?