mlflow/mlflow · error · TypeError
outputs must be either None, mlflow.models.signature.Schema,
Error message
outputs must be either None, mlflow.models.signature.Schema, or a dataclass,got '{type(outputs).__name__}' What it means
A TypeError raised by `ModelSignature.__init__` in mlflow/models/signature.py:87 when the `outputs` argument is neither None, a `Schema`, nor a dataclass. It mirrors the inputs validation: only explicitly supported types are accepted so signature metadata can be reliably serialized.
Source
Thrown at mlflow/models/signature.py:87
dataset, model predictions using and params for inference, or constructed by hand by
passing an input and output :py:class:`Schema <mlflow.types.Schema>`, and params
:py:class:`ParamSchema <mlflow.types.ParamSchema>`.
"""
def __init__(
self,
# `dataclass` is an invalid type annotation. Use `Any` instead as a workaround.
inputs: Schema | Any = None,
outputs: Schema | Any = None,
params: ParamSchema = None,
):
if inputs and not isinstance(inputs, Schema) and not is_dataclass(inputs):
raise TypeError(
"inputs must be either None, mlflow.models.signature.Schema, or a dataclass,"
f"got '{type(inputs).__name__}'"
)
if outputs and not isinstance(outputs, Schema) and not is_dataclass(outputs):
raise TypeError(
"outputs must be either None, mlflow.models.signature.Schema, or a dataclass,"
f"got '{type(outputs).__name__}'"
)
if params and not isinstance(params, ParamSchema):
raise TypeError(
"If params are provided, they must by of type mlflow.models.signature.ParamSchema, "
f"got '{type(params).__name__}'"
)
if all(x is None for x in [inputs, outputs, params]):
raise ValueError("At least one of inputs, outputs or params must be provided")
if is_dataclass(inputs):
self.inputs = convert_dataclass_to_schema(inputs)
else:
self.inputs = inputs
if is_dataclass(outputs):
self.outputs = convert_dataclass_to_schema(outputs)
else:
self.outputs = outputsView on GitHub (pinned to 6a27f2decc)
Solutions
- Build the signature with `infer_signature(model_input, model_output)` so outputs are converted to a Schema automatically.
- Pass an explicit `mlflow.models.signature.Schema` for outputs.
- Pass a dataclass instance describing outputs if you prefer typed definitions.
Example fix
// before ModelSignature(inputs=schema, outputs=y_array) # ndarray not allowed // after sig = infer_signature(X, y_array)
Defensive patterns
Strategy: type-guard
Validate before calling
from mlflow.models.signature import Schema
from dataclasses import is_dataclass
def validate_outputs_arg(outputs) -> None:
if outputs and not isinstance(outputs, Schema) and not is_dataclass(outputs):
raise TypeError(f'outputs must be Schema or dataclass, got {type(outputs).__name__}') Type guard
def is_valid_signature_outputs(x) -> bool:
from mlflow.models.signature import Schema
from dataclasses import is_dataclass
return x is None or isinstance(x, Schema) or is_dataclass(x) Try / catch
try:
sig = ModelSignature(inputs=schema, outputs=raw_predictions)
except TypeError:
sig = infer_signature(X, raw_predictions) Prevention
- Derive outputs from infer_signature(model_input, model_output).
- Never pass raw arrays/DataFrames as outputs to ModelSignature.
- Add a constructor-level assertion in helper code that wraps signature building.
When it happens
Trigger: Constructing `ModelSignature(inputs=..., outputs=...)` with raw example outputs (DataFrame, array, dict, list) rather than a Schema or dataclass instance.
Common situations: Manually assembling signatures with prediction output samples, refactored code that swapped infer_signature for direct construction.
Understand the failure class
Background: Invalid argument type errors: "must be of type string", "expected X, got Y", and ERR_INVALID_ARG_TYPE explained — this error's family across 15 libraries.
Related errors
- inputs must be either None, mlflow.models.signature.Schema,
- INVALID_PARAMETER_VALUE
- If params are provided, they must by of type mlflow.models.s
- At least one of inputs, outputs or params must be provided
- `{key}` must be of type {val_type.__name__}, got {type(value
AI-assisted analysis of mlflow/mlflow@6a27f2decc (2026-08-29).
Data as JSON: /api/errors/b8aeb4bf951ff66a.
Report an issue: GitHub.