mlflow/mlflow · error · MlflowException
Dictionary value must not be an empty numpy array.
Error message
Dictionary value must not be an empty numpy array.
What it means
When inferring schema for dict input examples, each value must yield a concrete dtype. If a dict value is an empty numpy array, `_infer_datatype` returns None and MLflow raises this error, because an Object property cannot have an empty-array (untyped) dtype.
Source
Thrown at mlflow/types/utils.py:159
raise InvalidDataForSignatureInferenceError(
message="MLflow does not support inferring model signature from input example "
"with Pydantic objects. To use Pydantic objects, define your PythonModel's "
"`predict` method with a Pydantic type hint, and model signature will be automatically "
"inferred when logging the model. e.g. "
"`def predict(self, model_input: list[PydanticType])`. Check "
"https://mlflow.org/docs/latest/model/python_model.html#type-hint-usage-in-pythonmodel "
"for more details."
)
if _is_none_or_nan(data) or (isinstance(data, (list, dict)) and not data):
return AnyType()
if isinstance(data, dict):
properties = []
for k, v in data.items():
dtype = _infer_datatype(v)
if dtype is None:
raise MlflowException("Dictionary value must not be an empty numpy array.")
properties.append(
Property(name=k, dtype=dtype, required=not isinstance(dtype, AnyType))
)
return Object(properties=properties)
if isinstance(data, (list, np.ndarray)):
return _infer_array_datatype(data)
return _infer_scalar_datatype(data)
def _infer_array_datatype(data: list[Any] | np.ndarray) -> Array | None:
"""Infer schema from an array. This tries to infer type if there is at least one
non-null item in the list, assuming the list has a homogeneous type. However,
if the list is empty or all items are null, returns None as a sign of undetermined.
E.g.
["a", "b"] => Array(string)View on GitHub (pinned to 6a27f2decc)
Solutions
- Replace empty arrays with a one-element sample array of the right dtype
- Drop the key from the example dict or set it to None if optional
- Use lists (inferred as Array(Any)) instead of empty numpy arrays if type precision isn't needed
Example fix
// before
infer_signature(model, {"x": np.array([])})
// after
infer_signature(model, {"x": np.array([1.0])}) Defensive patterns
Strategy: validation
Validate before calling
import numpy as np
def validate_dict_example(d):
for k, v in d.items():
if isinstance(v, np.ndarray) and v.size == 0:
raise ValueError(f"dict value for key {k!r} is an empty numpy array") Type guard
def is_empty_ndarray(v):
import numpy as np
return isinstance(v, np.ndarray) and v.size == 0 Try / catch
from mlflow.exceptions import MlflowException
try:
sig = infer_signature(model, example_dict)
except MlflowException as e:
if 'empty numpy array' in e.message:
example_dict = {k: v for k, v in example_dict.items() if not is_empty_ndarray(v)}
sig = infer_signature(model, example_dict) Prevention
- Scrub empty numpy arrays from example dicts before inferring signatures
- Use one-element sample arrays with correct dtype
- Drop or None-out optional keys that may be empty
When it happens
Trigger: Calling `infer_signature(model, {"a": 1, "feats": np.array([])})` — any key mapping to an empty numpy array triggers the error during dict inference.
Common situations: Empty feature vectors in example rows; default-initialized placeholders; data filtered down to zero-length arrays before logging the model.
Related errors
- Expected numpy.ndarray or csc/csr matrix, got '{type(data)}'
- The specified variable_dimension {variable_dimension} is out
- Expected `type` to be instance of `{np.dtype}`, received `{d
- Numpy array must include at least one non-empty item. Invali
- Shape of input {actual_shape} does not match expected shape
AI-assisted analysis of mlflow/mlflow@6a27f2decc (2026-08-29).
Data as JSON: /api/errors/0e53cf9129bf307f.
Report an issue: GitHub.