{"record":{"id":"0e53cf9129bf307f","repo":"mlflow/mlflow","slug":"dictionary-value-must-not-be-an-empty-numpy-array","errorCode":null,"errorMessage":"Dictionary value must not be an empty numpy array.","messagePattern":"Dictionary value must not be an empty numpy array\\.","errorType":"validation","errorClass":"MlflowException","httpStatus":null,"severity":"error","filePath":"mlflow/types/utils.py","lineNumber":159,"sourceCode":"        raise InvalidDataForSignatureInferenceError(\n            message=\"MLflow does not support inferring model signature from input example \"\n            \"with Pydantic objects. To use Pydantic objects, define your PythonModel's \"\n            \"`predict` method with a Pydantic type hint, and model signature will be automatically \"\n            \"inferred when logging the model. e.g. \"\n            \"`def predict(self, model_input: list[PydanticType])`. Check \"\n            \"https://mlflow.org/docs/latest/model/python_model.html#type-hint-usage-in-pythonmodel \"\n            \"for more details.\"\n        )\n\n    if _is_none_or_nan(data) or (isinstance(data, (list, dict)) and not data):\n        return AnyType()\n\n    if isinstance(data, dict):\n        properties = []\n        for k, v in data.items():\n            dtype = _infer_datatype(v)\n            if dtype is None:\n                raise MlflowException(\"Dictionary value must not be an empty numpy array.\")\n            properties.append(\n                Property(name=k, dtype=dtype, required=not isinstance(dtype, AnyType))\n            )\n        return Object(properties=properties)\n\n    if isinstance(data, (list, np.ndarray)):\n        return _infer_array_datatype(data)\n\n    return _infer_scalar_datatype(data)\n\n\ndef _infer_array_datatype(data: list[Any] | np.ndarray) -> Array | None:\n    \"\"\"Infer schema from an array. This tries to infer type if there is at least one\n    non-null item in the list, assuming the list has a homogeneous type. However,\n    if the list is empty or all items are null, returns None as a sign of undetermined.\n\n    E.g.\n        [\"a\", \"b\"] => Array(string)","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/mlflow/mlflow/blob/6a27f2decc0b76eb1b54af31849784addb357dbc/mlflow/types/utils.py#L141-L177","documentation":"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.","triggerScenarios":"Calling `infer_signature(model, {\"a\": 1, \"feats\": np.array([])})` — any key mapping to an empty numpy array triggers the error during dict inference.","commonSituations":"Empty feature vectors in example rows; default-initialized placeholders; data filtered down to zero-length arrays before logging the model.","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"],"exampleFix":"// before\ninfer_signature(model, {\"x\": np.array([])})\n// after\ninfer_signature(model, {\"x\": np.array([1.0])})","handlingStrategy":"validation","validationCode":"import numpy as np\ndef validate_dict_example(d):\n    for k, v in d.items():\n        if isinstance(v, np.ndarray) and v.size == 0:\n            raise ValueError(f\"dict value for key {k!r} is an empty numpy array\")","typeGuard":"def is_empty_ndarray(v):\n    import numpy as np\n    return isinstance(v, np.ndarray) and v.size == 0","tryCatchPattern":"from mlflow.exceptions import MlflowException\ntry:\n    sig = infer_signature(model, example_dict)\nexcept MlflowException as e:\n    if 'empty numpy array' in e.message:\n        example_dict = {k: v for k, v in example_dict.items() if not is_empty_ndarray(v)}\n        sig = infer_signature(model, example_dict)","preventionTips":["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"],"tags":["mlflow","numpy","signature","dict"],"backgroundTag":"empty-array-signature-inference","analyzedSha":"6a27f2decc0b76eb1b54af31849784addb357dbc","analyzedAt":"2026-08-29T20:54:51.419Z","schemaVersion":2},"datasetVersion":"2026-08-29T22:17:34.462Z"}