Sub topic 8
Check Schema, Code, Dependency, and State Compatibility
Before rolling back a model, verify that the older model can run safely in the current production environment. A model artifact is only one part of a deployed system. The serving code, input schema, libraries, feature pipeline, and stored state must also be compatible.
This chapter assumes you understand basic model deployment, production monitoring, APIs, and version control.
What must be compatible
A rollback can fail even when the selected model artifact is correct. Check these boundaries:
| Compatibility area | What to compare | Common failure |
|---|---|---|
| Input schema | Feature names, types, order, and missing-value rules | The old model receives a new feature or a changed type |
| Output contract | Prediction shape, labels, scores, and metadata | A client expects fields the old model does not return |
| Serving code | Preprocessing, postprocessing, and API behavior | Current code interprets the old model incorrectly |
| Dependencies | Runtime, framework, library, and operating-system versions | A serialized model cannot be loaded |
| State | Feature statistics, tokenizers, caches, and database records | The old model uses state created for the newer model |
Compatibility means more than “the service starts.” The old version must produce valid predictions and preserve downstream behavior.
Compare version manifests
Keep a manifest with every release. It should record the model version, artifact digest, schema version, code revision, dependency lockfile, and state format.
from dataclasses import dataclass
@dataclass(frozen=True)
class ReleaseManifest:
model_version: str
schema_version: str
code_revision: str
dependency_lock: str
state_format: str
def compatible_for_rollback(
target: ReleaseManifest,
current: ReleaseManifest,
) -> tuple[bool, list[str]]:
problems = []
if target.schema_version != current.schema_version:
problems.append("schema versions differ")
if target.state_format != current.state_format:
problems.append("state formats differ")
if target.dependency_lock != current.dependency_lock:
problems.append("dependency locks differ")
return not problems, problems
known_good = ReleaseManifest(
"2026.03.08", "features-v4", "git:abc123", "lock:python-3.12", "state-v2"
)
current = ReleaseManifest(
"2026.03.15", "features-v4", "git:def456", "lock:python-3.12", "state-v2"
)
ok, problems = compatible_for_rollback(known_good, current)
print("compatible:", ok)
print("problems:", problems)A code revision or dependency difference is not automatically unsafe. It requires testing. For example, a newer serving layer may still load an older model, while an older layer may not understand a newly introduced model format.
Handle incompatible state
State includes data that the model does not contain directly. Examples include normalization statistics, vocabulary files, feature-store snapshots, calibration parameters, and online learning checkpoints.
Ask these questions before changing traffic:
- Can the target model read the current state format?
- Can you restore a matching state snapshot?
- Will reverting state lose new data or create inconsistent records?
- Can the model run in stateless mode during the rollback?
- Do caches need to be cleared or warmed again?
Prefer versioned, immutable state snapshots. If state cannot be safely reversed, use a compatibility adapter or roll back the model and serving code without reverting shared state.
Test the rollback boundary
Use a staging environment with production-like inputs. Load the target artifact with the intended serving image, replay representative requests, and compare:
- request validation and response schema;
- prediction distributions and key quality metrics;
- error rate, latency, and resource use;
- feature freshness and missing-value rates;
- downstream actions such as ranking, alerts, or decisions.
If any boundary fails, stop the rollback and choose a compatible deployment unit. Record the test evidence, manifest versions, and unresolved risks in the change record.
Exercise
The older model loads successfully, but its output omits a field required by downstream clients. Should you send production traffic to it?
Show answer
No. The model is not compatible with the output contract. Add a tested adapter, deploy a compatible serving version, or select another known-good release before shifting traffic.