Skip to main content

Fixed: "Encountered unexpected error during sklearn autologging: The saved sklearn model references untrusted types"

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

I turned on MLflow's scikit-learn autologging with the safer skops format, and a gradient-boosted model's run ended with WARNING mlflow.utils.autologging_utils: Encountered unexpected error during sklearn autologging: The saved sklearn model references untrusted types. The model was marked Failed, and the run had no metrics at all. Autologging has no way to pass skops the types to trust; logging the model myself with log_model(..., skops_trusted_types=[...]), with autologging's models turned off, fixed it.

What I Was Doing​

While building the MLflow series, I wanted autologging to save models in the skops format instead of its default, cloudpickle. On MLflow 3.18.0 and scikit-learn 1.9.1, I trained a HistGradientBoostingRegressor on scikit-learn's diabetes data with autologging set to skops:

autolog_skops.py
import mlflow
from sklearn.datasets import load_diabetes
from sklearn.ensemble import HistGradientBoostingRegressor

mlflow.set_tracking_uri("http://127.0.0.1:8080")
mlflow.set_experiment("autolog-skops-demo")
mlflow.sklearn.autolog(serialization_format="skops")

X, y = load_diabetes(return_X_y=True, as_frame=True)
model = HistGradientBoostingRegressor(random_state=0).fit(X, y)
Terminal
uv run python autolog_skops.py

What I Expected​

An autologged run with the model's parameters, training metrics and the model, saved as model.skops.

What I Got​

The run was created and closed, and then a warning:

Output (excerpt)
🏃 View run delicate-tern-811 at: http://127.0.0.1:8080/#/experiments/21/runs/44a935ee655640f093fab1cbf6343df3
🧪 View experiment at: http://127.0.0.1:8080/#/experiments/21
2026/11/21 14:27:10 WARNING mlflow.utils.autologging_utils: Encountered unexpected error during sklearn autologging: The saved sklearn model references untrusted types. If you are sure loading these types is safe, set the 'skops_trusted_types' parameter when calling 'log_model' or 'save_model' to the list of trusted types. Root error: Untrusted types found in the file: ['sklearn.ensemble._hist_gradient_boosting.predictor.TreePredictor'].

- sklearn.ensemble._hist_gradient_boosting.predictor.TreePredictor: sklearn.ensemble._hist_gradient_boosting.predictor.TreePredictor (used by HistGradientBoosting* models) stores raw node indices (left, right, feature_idx) in its nodes array that scikit-learn indexes into without bounds checking. A malicious file can set these to out-of-range values: skops loads the object successfully, but calling .predict() on it can then crash the process (segfault) or read out-of-bounds memory. If you created the file yourself or otherwise fully trust its source, you can load it with trusted=["sklearn.ensemble._hist_gradient_boosting.predictor.TreePredictor"].

Only add the specific types you have reviewed and trust to the `trusted` argument; avoid passing everything reported by get_untrusted_types() just to make a file load.

The output of autolog_skops.py in a terminal: after the run's link, a WARNING from mlflow.utils.autologging_utils: Encountered unexpected error during sklearn autologging, The saved sklearn model references untrusted types, naming TreePredictor and skops's explanation of its risk.

The run itself, delicate-tern-811, has its 21 parameters but no metrics:

The run's Metrics (0) section: an empty table with the message No metrics recorded.

What I Checked​

The message. It names the fix for direct calls: "set the 'skops_trusted_types' parameter when calling 'log_model' or 'save_model'". TreePredictor is the object each of the model's trees is stored in, and skops explains why it isn't trusted by default.

Autologging's options. The reference for mlflow.sklearn.autolog lists serialization_format, log_models and others, but no skops_trusted_types. There's no way to hand autologging the list.

What was lost. The model's entry on the experiment's Models tab has the status Failed, and the run has no training metrics. The error interrupted autologging after the parameters were logged.

Why It Happens​

skops refuses to save a model whose types it couldn't load back safely, unless you list them as trusted. A HistGradientBoosting* model holds TreePredictor objects, which skops doesn't trust by default. log_model and save_model take the list, skops_trusted_types; autologging doesn't, so its save fails, and it stops logging that model's metrics.

The Fix​

Keep autologging for the parameters and metrics, turn its models off, and save the model yourself with the reviewed type listed:

The fixed autolog_skops_fixed.py in a macOS-style code window: autolog with log_models False, a TRUSTED_TYPES list holding TreePredictor, and inside a run the model is fitted and logged with mlflow.sklearn.log_model, an input example, serialization_format skops and skops_trusted_types.

autolog_skops_fixed.py
import mlflow
from sklearn.datasets import load_diabetes
from sklearn.ensemble import HistGradientBoostingRegressor

mlflow.set_tracking_uri("http://127.0.0.1:8080")
mlflow.set_experiment("autolog-skops-demo")
# Autologging keeps the parameters and metrics; the model is saved below, with its trusted types.
mlflow.sklearn.autolog(log_models=False)

TRUSTED_TYPES = ["sklearn.ensemble._hist_gradient_boosting.predictor.TreePredictor"]

X, y = load_diabetes(return_X_y=True, as_frame=True)
with mlflow.start_run():
model = HistGradientBoostingRegressor(random_state=0).fit(X, y)
mlflow.sklearn.log_model(
model,
name="model",
input_example=X.head(3),
serialization_format="skops",
skops_trusted_types=TRUSTED_TYPES,
)

The list is written out on purpose, after reading skops's explanation: a model I trained myself is a source I trust.

After the Fix​

Terminal
uv run python autolog_skops_fixed.py
Output
2026/11/21 14:27:15 INFO mlflow.utils.uv_utils: Detected uv project: found uv.lock and pyproject.toml in /Users/you/source/mlflow-demo
2026/11/21 14:27:16 INFO mlflow.utils.uv_utils: Detected uv project: found uv.lock and pyproject.toml in /Users/you/source/mlflow-demo
2026/11/21 14:27:16 INFO mlflow.utils.environment: Detected uv project at /Users/you/source/mlflow-demo. Attempting to export requirements via 'uv export'.
2026/11/21 14:27:16 INFO mlflow.utils.uv_utils: Exported 91 dependencies via uv
2026/11/21 14:27:16 INFO mlflow.utils.environment: Successfully exported 91 requirements from uv project. Skipping package capture based inference.
🏃 View run wise-midge-523 at: http://127.0.0.1:8080/#/experiments/21/runs/90bb944ce22f4034876b8ab8eaee95d2
🧪 View experiment at: http://127.0.0.1:8080/#/experiments/21

The output of autolog_skops_fixed.py in a terminal: the uv export lines and the run's link, with no warning.

No warning. The experiment's Models tab shows both attempts:

The autolog-skops-demo Models tab: the model from autolog_skops_fixed.py, run wise-midge-523, is Ready; the one from autolog_skops.py, run delicate-tern-811, is Failed.

The new model is Ready, and its run has the training metrics autologging records, such as training_mean_squared_error.

Common Mistakes​

MistakeWhat happensDo this instead
Trusting every type get_untrusted_types reports, unreadThe protection skops gives is goneReview each type and write out the list
Going back to cloudpickle to silence itThe model can run code when loadedKeep skops and list the trusted types

Troubleshooting​

SymptomLikely causeFix
MlflowException: The saved sklearn model references untrusted types from log_modelThe same check, without the listFixed: The saved sklearn model references untrusted types
A logged model's status is FailedSaving it failed during loggingCheck the output for the error

FAQ​

Does this happen with every model?​

No. Models made only of types skops trusts, such as a linear regression, save in the skops format with autologging. Tree ensembles like HistGradientBoosting* hold a type it doesn't.

Do I lose anything by logging the model myself?​

No: autologging still records the parameters and metrics, and log_model saves the model, with an input example if you pass one.

Conclusion​

Autologging couldn't save a HistGradientBoostingRegressor in the skops format, because skops needed TreePredictor listed as trusted and autologging has no parameter for it. The model failed and the run lost its metrics. With autolog(log_models=False) and log_model(..., skops_trusted_types=[...]), the run got its metrics and the model saved as Ready.

Additional Resources​