mlflow/mlflow · error · MlflowException

Map types are incompatible for {self} with value_type={self.

Error message

Map types are incompatible for {self} with value_type={self.value_type} and {other} with value_type={other.value_type}

What it means

When both operands of Map._merge are Maps but the left map's value_type is a simple DataType, the value types must be exactly equal (e.g. both double). Otherwise MLflow cannot decide a common value type and raises this error listing both incompatible maps.

Source

Thrown at mlflow/types/schema.py:672

        if kwargs["values"]["type"] == ARRAY_TYPE:
            return cls(value_type=Array.from_json_dict(**kwargs["values"]))
        if kwargs["values"]["type"] == SPARKML_VECTOR_TYPE:
            return SparkMLVector()
        if kwargs["values"]["type"] == MAP_TYPE:
            return cls(value_type=Map.from_json_dict(**kwargs["values"]))
        if kwargs["values"]["type"] == ANY_TYPE:
            return cls(value_type=AnyType())
        return cls(value_type=kwargs["values"]["type"])

    def _merge(self, other: BaseType) -> Map:
        if isinstance(other, AnyType) or self == other:
            return deepcopy(self)
        if not isinstance(other, Map):
            raise MlflowException(f"Can't merge map with non-map type: {type(other).__name__}")
        if isinstance(self.value_type, DataType):
            if self.value_type == other.value_type:
                return Map(value_type=self.value_type)
            raise MlflowException(
                f"Map types are incompatible for {self} with value_type={self.value_type} and "
                f"{other} with value_type={other.value_type}"
            )

        if isinstance(self.value_type, (Array, Object, Map, AnyType)):
            return Map(value_type=self.value_type._merge(other.value_type))

        raise MlflowException(f"Map type {self!r} and {other!r} are incompatible")


class AnyType(BaseType):
    def __init__(self):
        """
        AnyType can store any json-serializable data including None values.
        For example:

        .. code-block::python

View on GitHub (pinned to 6a27f2decc)

Solutions

  1. Align the map value types exactly: cast the data (e.g. df['col'] = df['col'].astype('float64')) so both signatures use the same DataType.
  2. Re-infer the signature on the final, consistently-typed data with infer_signature and re-log the model.
  3. If either value type is genuinely flexible, change one side to AnyType() so the merge produces the concrete other type.
  4. For composite value types (Array/Object/Map), ensure the nested types are also mergeable; nested mismatches surface from the inner _merge.

Example fix

// before
Map(value_type=DataType.double)._merge(Map(value_type=DataType.float))
// raises: Map types are incompatible ...

// after
Map(value_type=DataType.double)._merge(Map(value_type=DataType.double))
Defensive patterns

Strategy: validation

Validate before calling

from mlflow.types.schema import Map, DataType

def maps_have_matching_value_types(a: Map, b: Map) -> bool:
    if isinstance(a.value_type, DataType) and isinstance(b.value_type, DataType):
        return a.value_type == b.value_type
    return True

Type guard

def same_map_value_type(a: Map, b: Map) -> bool:
    return isinstance(a.value_type, DataType) and a.value_type == b.value_type

Try / catch

from mlflow.exceptions import MlflowException
try:
    merged = map_a._merge(map_b)
except MlflowException as e:
    if "Map types are incompatible" in str(e):
        cast_data_to_common_dtype()  # e.g. astype('float64') then re-infer signature
    else:
        raise

Prevention

When it happens

Trigger: Merging two Map columns whose value types differ, e.g. Map(value_type=DataType.double)._merge(Map(value_type=DataType.float)) or Map(string) vs Map(long), via Schema merging during signature unification or schema enforcement.

Common situations: Numeric drift between training and serving signatures (double vs float, long vs int); one team logged signatures with float32 pandas columns and another with float64; map<string, bool> vs map<string, string> after a feature change; comparing models served from different framework versions that infer different dtypes.

Related errors


AI-assisted analysis of mlflow/mlflow@6a27f2decc (2026-08-29). Data as JSON: /api/errors/ef1d6a9f039ce390. Report an issue: GitHub.