mlflow/mlflow · error · TypeError
Argument 'mlflow_model' should be mlflow.models.Model, got '
Error message
Argument 'mlflow_model' should be mlflow.models.Model, got '{type(mlflow_model)}' What it means
FileStore.record_logged_model requires mlflow_model to be an instance of mlflow.models.Model and raises a plain TypeError for anything else. It is an internal API type check to prevent writing invalid logged-model tags.
Source
Thrown at mlflow/store/tracking/file_store.py:1281
model_id=metric.model_id,
run_id=run_id,
metric=metric,
)
for tag in tags:
# NB: If the tag run name value is set, update the run info to assure
# synchronization.
if tag.key == MLFLOW_RUN_NAME:
run_status = RunStatus.from_string(run_info.status)
self.update_run_info(run_id, run_status, run_info.end_time, tag.value)
self._set_run_tag(run_info, tag)
except Exception as e:
raise MlflowException(e, INTERNAL_ERROR)
def record_logged_model(self, run_id, mlflow_model):
from mlflow.models import Model
if not isinstance(mlflow_model, Model):
raise TypeError(
f"Argument 'mlflow_model' should be mlflow.models.Model, got '{type(mlflow_model)}'"
)
_validate_run_id(run_id)
run_info = self._get_run_info(run_id)
check_run_is_active(run_info)
model_dict = mlflow_model.get_tags_dict()
run_info = self._get_run_info(run_id)
path = self._get_tag_path(run_info.experiment_id, run_info.run_id, MLFLOW_LOGGED_MODELS)
if os.path.exists(path):
with open(path) as f:
model_list = json.loads(f.read())
else:
model_list = []
tag = RunTag(MLFLOW_LOGGED_MODELS, json.dumps(model_list + [model_dict]))
try:
self._set_run_tag(run_info, tag)
except Exception as e:View on GitHub (pinned to 6a27f2decc)
Solutions
- Pass an actual mlflow.models.Model instance (e.g. the object from Model.load or the model you saved)
- If you have a dict, construct Model.from_dict(model_dict) before calling
- Check you are importing Model from mlflow.models, not a similarly named registry entity class
- Use the public mlflow.log_model / MlflowClient.log_logged_model APIs instead of the internal record_logged_model
Example fix
// before from mlflow.entities import Model store.record_logged_model(run_id, model_dict) // after from mlflow.models import Model store.record_logged_model(run_id, Model.from_dict(model_dict))
Defensive patterns
Strategy: type-guard
Validate before calling
from mlflow.models import Model
if not isinstance(mlflow_model, Model):
raise TypeError("record_logged_model requires mlflow.models.Model") Type guard
from mlflow.models import Model
def is_mlflow_model(obj) -> bool:
return isinstance(obj, Model) Try / catch
try:
store.record_logged_model(run_id, model)
except TypeError as e:
model = Model.from_dict(model_as_dict)
store.record_logged_model(run_id, model) Prevention
- Always import Model from mlflow.models, never mlflow.entities
- Prefer public APIs (mlflow.log_model, MlflowClient.create_logged_model) over internal store methods
- Convert dicts with Model.from_dict before passing
When it happens
Trigger: Calling FileStore.record_logged_model (or a code path that forwards into it) with a dict, an mlflow.entities.model_registry.Model, a LoggedModel, or any object that is not mlflow.models.Model.
Common situations: Hand-rolled logging code passing a model dict or registry model instead of a loaded mlflow.models.Model; mixing up mlflow.models.Model with mlflow.entities.Model in custom integrations; version changes where internal helpers expect Model.
Understand the failure class
Background: "Wrong argument type", "must be a string", "expected Array or Prism::Scope": TypeError and ArgumentError when a library receives a value of the wrong type — this error's family across 28 libraries.
Related errors
- The `requestPreview` parameter must be a string.
- The `responsePreview` parameter must be a string.
- trackingUri must be a string
- experimentId must be a string
- Logged model {model_id} is not in `deleted` lifecycle stage.
AI-assisted analysis of mlflow/mlflow@6a27f2decc (2026-08-29).
Data as JSON: /api/errors/ad29b160b08bdd47.
Report an issue: GitHub.