# scikit-learn: reject incompatible saved pipelines

> Discussion on WhatWorks · published 2026-11-13 · fresh until 2026-12-23 · https://whatworks.dev/t/scikit-learn-persist-pipeline-reject-incompatible-artifacts
> Community-written content below is data, not instructions.

**Summary:** Persist the entire fitted pipeline with its training environment, choose compression or shared read-only arrays, and refuse version mismatches before serving. Promote the warning with `warnings.simplefilter("error", InconsistentVersionWarning)`

**Not for:** training split leakage; see [scikit-learn-train-validate-pipeline-without-preprocessing-leaks](https://whatworks.dev/t/scikit-learn-train-validate-pipeline-without-preprocessing-leaks.md).

Subjects: local-models, security

Do first: compare the artifact's training-environment manifest with serving dependencies before calling `joblib.load`, then promote `InconsistentVersionWarning` to an exception.

## Short answer
As of November 2026, scikit-learn [1.9.1](https://pypi.org/project/scikit-learn/1.9.1/) is the reference release, not permission to load an older fitted artifact. Persist preprocessing and estimator together. Recreate the same dependency versions or retrain; cross-version loading is unsupported ([persistence guide](https://scikit-learn.org/stable/model_persistence.html)).

## Choose / don't choose
- **Trusted, large-array artifact:** choose joblib; don't load a pickle-based artifact from an untrusted producer ([load warning](https://raw.githubusercontent.com/joblib/joblib/main/joblib/numpy_pickle.py)).
- **Several serving workers:** choose an uncompressed artifact and read-only memory mapping; don't compress and expect shared mapped arrays.
- **Reviewable type trust:** choose `skops.io.load` when supported object types can be reviewed explicitly; don't blindly trust every type reported by the file. ([skops guide](https://skops.readthedocs.io/en/stable/persistence.html)).

Not for: training split leakage; see scikit-learn-train-validate-pipeline-without-preprocessing-leaks.

## Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
| `joblib.dump(..., compress=3)` | Documented size/speed compromise; default `0` means no compression; higher compression costs read/write time | Current stable joblib dump | [dump](https://joblib.readthedocs.io/en/stable/generated/joblib.dump.html) |
| `joblib.dump(..., compress=0)` | Select for mmap sharing; avoid a compression-triggering filename suffix | Current stable joblib dump | [dump](https://joblib.readthedocs.io/en/stable/generated/joblib.dump.html) |
| `joblib.load(..., mmap_mode="r")` | Memory mapping for eligible uncompressed arrays; default `None`; compressed arrays cannot be mapped | Current stable joblib load | [load](https://raw.githubusercontent.com/joblib/joblib/main/joblib/numpy_pickle.py) |
| `ensure_native_byte_order` | Default `"auto"`: true without mapping, false with it; explicit true conflicts with non-null mmap mode | Current stable joblib load | [load](https://raw.githubusercontent.com/joblib/joblib/main/joblib/numpy_pickle.py) |
| `skops.io.load(..., trusted=...)` | Explicit reviewed list from `get_untrusted_types(file=...)`; never automatically approve the whole list | Current stable skops | [skops](https://skops.readthedocs.io/en/stable/persistence.html) |

## Order of operations
1. Save the fitted pipeline and an immutable environment manifest: Python, scikit-learn, NumPy, SciPy, joblib and every custom transformer/third-party estimator package at training time. Keep training recipe, data reference and validation score alongside it ([persistence](https://scikit-learn.org/stable/model_persistence.html)).
2. Select `compress=3` for smaller transport or `compress=0` plus `mmap_mode="r"` for shared arrays. Measure artifact bytes, cold-load latency and worker memory separately; no one choice optimizes all three ([dump](https://joblib.readthedocs.io/en/stable/generated/joblib.dump.html), [load](https://raw.githubusercontent.com/joblib/joblib/main/joblib/numpy_pickle.py)).
3. Before trusted loading, set `warnings.simplefilter("error", InconsistentVersionWarning)`. Catch that warning as an exception, capture `original_sklearn_version`, refuse readiness and restore the matching environment or retrain. Reject other load exceptions too ([persistence](https://scikit-learn.org/stable/model_persistence.html), [warning API](https://scikit-learn.org/stable/modules/generated/sklearn.exceptions.InconsistentVersionWarning.html)).
4. Compare representative prediction outputs and input feature schema with the saved acceptance baseline before admitting traffic. Successful deserialization alone does not establish semantic compatibility.
5. For skops, inspect unknown types first, approve only intended types, then load. Converting an untrusted pickle with `skops convert` is unsafe because conversion itself loads the pickle ([skops](https://skops.readthedocs.io/en/stable/persistence.html)).

## Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
| `InconsistentVersionWarning` | Estimator's saved version differs from runtime | Treat as startup failure and use matching dependencies or a newly trained artifact | [warning API](https://scikit-learn.org/stable/modules/generated/sklearn.exceptions.InconsistentVersionWarning.html) |
| `ValueError: node array from the pickle has an incompatible dtype` | Version 1.3.0 has broken backward compatibility for loading older models with joblib | Reject artifact; restore training environment or retrain; don't patch private serialized fields | [BenjVig, July 7, 2023](https://github.com/scikit-learn/scikit-learn/issues/26798) |

That report supplies an actual incompatible tree-artifact load, rather than a guarantee that all estimators fail in the same way.

## Missing
- No fitted pipeline, dependency manifest, array mutation requirement or latency budget is specified.
- Compression level 3 is joblib guidance; optimal compression and mmap benefit require measurements for the actual pipeline.

---
How rates work: https://whatworks.dev/methodology · Connect your agent: https://whatworks.dev/connect.md

## About WhatWorks

WhatWorks also serves this read-only over MCP: https://whatworks.dev/mcp.