mlflow/mlflow · error · MlflowException

The specified variable_dimension {variable_dimension} is out

Error message

The specified variable_dimension {variable_dimension} is out of bounds with respect to the number of dimensions {data.ndim} in the input dataset

What it means

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.

Source

Thrown at mlflow/types/utils.py:67

    Args:
        data: Dataset to infer from.
        variable_dimension: An optional integer representing a variable dimension.

    Returns:
        tuple: Shape of the inputted data (including a variable dimension)
    """
    from scipy.sparse import csc_matrix, csr_matrix

    if not isinstance(data, (np.ndarray, csr_matrix, csc_matrix)):
        raise TypeError(f"Expected numpy.ndarray or csc/csr matrix, got '{type(data)}'.")
    variable_input_data_shape = data.shape
    if variable_dimension is not None:
        try:
            variable_input_data_shape = list(variable_input_data_shape)
            variable_input_data_shape[variable_dimension] = -1
        except IndexError:
            raise MlflowException(
                f"The specified variable_dimension {variable_dimension} is out of bounds with "
                f"respect to the number of dimensions {data.ndim} in the input dataset"
            )
    return tuple(variable_input_data_shape)


def clean_tensor_type(dtype: np.dtype):
    """
    This method strips away the size information stored in flexible datatypes such as np.str_ and
    np.bytes_. Other numpy dtypes are returned unchanged.

    Args:
        dtype: Numpy dtype of a tensor

    Returns:
        dtype: Cleaned numpy dtype
    """
    if not isinstance(dtype, np.dtype):

View on GitHub (pinned to 6a27f2decc)

Solutions

  1. Set `variable_dimension` to a valid axis index (0 <= dim < data.ndim)
  2. Check `data.ndim` before passing variable_dimension
  3. Pass `variable_dimension=None` if no axis is variable

Example fix

// before
_infer_schema(data=np.zeros((4, 5)), variable_dimension=2)  # 2D array
// after
_infer_schema(data=np.zeros((4, 5)), variable_dimension=1)
Defensive patterns

Strategy: validation

Validate before calling

if variable_dimension is not None and not (0 <= variable_dimension < data.ndim):
    raise ValueError(f"variable_dimension {variable_dimension} out of range for ndim {data.ndim}")

Type guard

def is_valid_variable_dim(data, dim):
    return dim is None or 0 <= dim < len(data.shape)

Try / catch

from mlflow.exceptions import MlflowException
try:
    schema = _infer_schema(data, variable_dimension=dim)
except MlflowException as e:
    schema = _infer_schema(data, variable_dimension=None)

Prevention

When it happens

Trigger: 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.

Common situations: Copy-pasting signature inference code between models with different input ranks; changing model input from fixed to variable dims without updating `variable_dimension`.

Related errors


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