{"record":{"id":"3cfd8d2fbdfdb9c7","repo":"mlflow/mlflow","slug":"invalid-data-type-data-type-r","errorCode":null,"errorMessage":"Invalid data type: {data_type!r}","messagePattern":"Invalid data type: (.+?)","errorType":"exception","errorClass":"MlflowException","httpStatus":null,"severity":"error","filePath":"mlflow/models/utils.py","lineNumber":1465,"sourceCode":"\n    if not all(isinstance(k, str) for k in data):\n        raise MlflowException(\"Expected all keys in the map type data are string type.\")\n\n    return {k: _enforce_type(v, map_type.value_type, required=required) for k, v in data.items()}\n\n\ndef _enforce_type(data: Any, data_type: DataType | Array | Object | Map, required=True):\n    if isinstance(data_type, DataType):\n        return _enforce_datatype(data, data_type, required=required)\n    if isinstance(data_type, Array):\n        return _enforce_array(data, data_type, required=required)\n    if isinstance(data_type, Object):\n        return _enforce_object(data, data_type, required=required)\n    if isinstance(data_type, Map):\n        return _enforce_map(data, data_type, required=required)\n    if isinstance(data_type, AnyType):\n        return data\n    raise MlflowException(f\"Invalid data type: {data_type!r}\")\n\n\ndef validate_schema(data: PyFuncInput, expected_schema: Schema) -> None:\n    \"\"\"\n    Validate that the input data has the expected schema.\n\n    Args:\n        data: Input data to be validated. Supported types are:\n\n            - pandas.DataFrame\n            - pandas.Series\n            - numpy.ndarray\n            - scipy.sparse.csc_matrix\n            - scipy.sparse.csr_matrix\n            - List[Any]\n            - Dict[str, Any]\n            - str\n","sourceCodeStart":1447,"sourceCodeEnd":1483,"githubUrl":"https://github.com/mlflow/mlflow/blob/6a27f2decc0b76eb1b54af31849784addb357dbc/mlflow/models/utils.py#L1447-L1483","documentation":"_enforce_type dispatches on the schema data type object (DataType, Array, Object, Map, AnyType). If the data_type argument is none of the recognized schema type classes, MLflow raises this error because it has no enforcement rule for it. This almost always means a raw Python type (like str or dict) or a foreign type object was passed where an mlflow.types schema type instance was expected.","triggerScenarios":"Constructing a Schema or calling _enforce_type / _enforce_col_schema paths with a plain Python type (e.g., str, dict) or an instance of a non-MLflow class instead of mlflow.types.DataType/Array/Object/Map instances.","commonSituations":"Building a Schema manually with Column('x', dict) instead of Column('x', DataType); mixing custom type wrappers into a Schema; version drift where a schema was serialized/deserialized incorrectly; passing a type class rather than an instance of mlflow.types schema types.","solutions":["Use mlflow.types.schema types: Column('x', DataType.from_python_type(str)) or infer_signature to generate the schema","Verify every Column/ParamSpec/TensorSpec data type is an instance of mlflow.types.DataType, Array, Object, or Map","Do not pass bare Python types into Schema construction; convert with DataType.from_python_type","Check mlflow version compatibility if the schema came from a saved model artifact"],"exampleFix":"// before\nschema = Schema([Column(\"x\", dict)])\n// after\nfrom mlflow.types.schema import Schema, Column, DataType\nschema = Schema([Column(\"x\", DataType.string)])","handlingStrategy":"type-guard","validationCode":"from mlflow.types.schema import DataType, Array, Object, Map\ndef check_schema_types(schema):\n    for col in schema.columns:\n        if not isinstance(col.type, (DataType, Array, Object, Map)):\n            raise TypeError(f\"column {col.name!r} has invalid type {type(col.type).__name__}\")","typeGuard":"def is_valid_mlflow_type(t) -> bool:\n    from mlflow.types.schema import DataType, Array, Object, Map\n    return isinstance(t, (DataType, Array, Object, Map))","tryCatchPattern":"from mlflow.exceptions import MlflowException\ntry:\n    validate_schema(data, schema)\nexcept MlflowException as e:\n    if \"Invalid data type\" in str(e):\n        raise ValueError(\"Rebuild schema with mlflow.types.schema types or infer_signature\") from e","preventionTips":["Never pass bare Python types into Schema; use DataType / DataType.from_python_type","Generate signatures with infer_signature rather than manual construction","Round-trip test schema save/load when persisting models","Pin and align mlflow versions between training and serving environments"],"tags":["mlflow","schema","type-system","python"],"backgroundTag":"schema-validation-failed","analyzedSha":"6a27f2decc0b76eb1b54af31849784addb357dbc","analyzedAt":"2026-08-29T20:54:51.419Z","schemaVersion":2},"datasetVersion":"2026-08-29T22:17:34.462Z"}