{"record":{"id":"16fa8e4036032bb6","repo":"mlflow/mlflow","slug":"the-specified-variable-dimension-variable-dimensi","errorCode":null,"errorMessage":"The specified variable_dimension {variable_dimension} is out of bounds with respect to the number of dimensions {data.ndim} in the input dataset","messagePattern":"The specified variable_dimension (.+?) is out of bounds with respect to the number of dimensions (.+?) in the input dataset","errorType":"validation","errorClass":"MlflowException","httpStatus":null,"severity":"error","filePath":"mlflow/types/utils.py","lineNumber":67,"sourceCode":"\n    Args:\n        data: Dataset to infer from.\n        variable_dimension: An optional integer representing a variable dimension.\n\n    Returns:\n        tuple: Shape of the inputted data (including a variable dimension)\n    \"\"\"\n    from scipy.sparse import csc_matrix, csr_matrix\n\n    if not isinstance(data, (np.ndarray, csr_matrix, csc_matrix)):\n        raise TypeError(f\"Expected numpy.ndarray or csc/csr matrix, got '{type(data)}'.\")\n    variable_input_data_shape = data.shape\n    if variable_dimension is not None:\n        try:\n            variable_input_data_shape = list(variable_input_data_shape)\n            variable_input_data_shape[variable_dimension] = -1\n        except IndexError:\n            raise MlflowException(\n                f\"The specified variable_dimension {variable_dimension} is out of bounds with \"\n                f\"respect to the number of dimensions {data.ndim} in the input dataset\"\n            )\n    return tuple(variable_input_data_shape)\n\n\ndef clean_tensor_type(dtype: np.dtype):\n    \"\"\"\n    This method strips away the size information stored in flexible datatypes such as np.str_ and\n    np.bytes_. Other numpy dtypes are returned unchanged.\n\n    Args:\n        dtype: Numpy dtype of a tensor\n\n    Returns:\n        dtype: Cleaned numpy dtype\n    \"\"\"\n    if not isinstance(dtype, np.dtype):","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/mlflow/mlflow/blob/6a27f2decc0b76eb1b54af31849784addb357dbc/mlflow/types/utils.py#L49-L85","documentation":"When inferring tensor schema, the `variable_dimension` argument lets a caller mark one axis as variable (-1). If that index exceeds the number of dimensions (`data.ndim`) of the input array, MLflow raises this MlflowException instead of silently mis-shaping the spec.","triggerScenarios":"Calling `infer_signature` (or internal `_infer_schema`) with a tensor input of shape (N,) but `variable_dimension=1`, or an out-of-range dimension like 3 for a 2D array.","commonSituations":"Copy-pasting signature inference code between models with different input ranks; changing model input from fixed to variable dims without updating `variable_dimension`.","solutions":["Set `variable_dimension` to a valid axis index (0 <= dim < data.ndim)","Check `data.ndim` before passing variable_dimension","Pass `variable_dimension=None` if no axis is variable"],"exampleFix":"// before\n_infer_schema(data=np.zeros((4, 5)), variable_dimension=2)  # 2D array\n// after\n_infer_schema(data=np.zeros((4, 5)), variable_dimension=1)","handlingStrategy":"validation","validationCode":"if variable_dimension is not None and not (0 <= variable_dimension < data.ndim):\n    raise ValueError(f\"variable_dimension {variable_dimension} out of range for ndim {data.ndim}\")","typeGuard":"def is_valid_variable_dim(data, dim):\n    return dim is None or 0 <= dim < len(data.shape)","tryCatchPattern":"from mlflow.exceptions import MlflowException\ntry:\n    schema = _infer_schema(data, variable_dimension=dim)\nexcept MlflowException as e:\n    schema = _infer_schema(data, variable_dimension=None)","preventionTips":["Verify data.ndim before choosing variable_dimension","Update variable_dimension when model input rank changes","Leave variable_dimension=None unless a dynamic axis is required"],"tags":["mlflow","numpy","signature","tensor"],"backgroundTag":"invalid-input-type-for-signature-inference","analyzedSha":"6a27f2decc0b76eb1b54af31849784addb357dbc","analyzedAt":"2026-08-29T20:54:51.419Z","schemaVersion":2},"datasetVersion":"2026-08-29T22:17:34.462Z"}