mlflow/mlflow · error · MlflowException
INVALID_PARAMETER_VALUE
INVALID_PARAMETER_VALUE
Error message
The specified input argument index ({input_arg_index}) is out of range for the function signature: {input_arg_index},{arg_names} What it means
Raised by `_extract_type_hints` in mlflow/models/signature.py when the requested `input_arg_index` points past the last argument of the function being inspected (after filtering out `self`). MLflow needs the type hint of the Nth input argument to infer a model signature, so an out-of-range index means the function has fewer signature arguments than expected.
Source
Thrown at mlflow/models/signature.py:335
"""
Extract type hints from a function.
Args:
f: Function to extract type hints from.
input_arg_index: Index of the function argument that corresponds to the model input.
Returns:
A `_TypeHints` object containing the input and output type hints.
"""
if not hasattr(f, "__annotations__") and hasattr(f, "__call__"):
return _extract_type_hints(f.__call__, input_arg_index)
if f.__annotations__ == {}:
return _TypeHints()
arg_names = list(filter(lambda x: x != "self", _get_arg_names(f)))
if len(arg_names) - 1 < input_arg_index:
raise MlflowException.invalid_parameter_value(
f"The specified input argument index ({input_arg_index}) is out of range for the "
"function signature: {}".format(input_arg_index, arg_names)
)
arg_name = arg_names[input_arg_index]
try:
hints = get_type_hints(f)
except (
TypeError,
NameError, # To handle this issue: https://github.com/python/typing/issues/797
):
# ---
# from __future__ import annotations # postpones evaluation of 'list[str]'
#
# def f(x: list[str]) -> list[str]:
# ^^^^^^^^^ Evaluating this expression ('list[str]') results in a TypeError in
# Python < 3.9 because the built-in list type is not subscriptable.
# return x
# ---View on GitHub (pinned to 6a27f2decc)
Solutions
- Add the missing argument(s) to the predict function signature so it has at least input_arg_index+1 non-self parameters, e.g. `def predict(self, model_input, params=None)`.
- Lower the `input_arg_index` passed to signature inference so it matches an existing argument.
- Verify the function is decorated/defined such that its argument names are introspectable (functools.wraps etc.) and `self` filtering matches expectations.
- Print `inspect.signature(fn).parameters` to confirm the actual argument list before inferring.
Example fix
// before
def predict(self, x):
...
mlflow.pyfunc.log_model("m", python_model=model) # input_arg_index=1
// after
def predict(self, context, model_input):
...
mlflow.pyfunc.log_model("m", python_model=model) Defensive patterns
Strategy: validation
Validate before calling
import inspect
n_args = len([p for p in inspect.signature(fn).parameters if p != "self"])
if n_args - 1 < input_arg_index:
raise ValueError(f"{fn} has only {n_args} args; input_arg_index={input_arg_index} is out of range") Type guard
def has_input_arg_index(fn, idx: int) -> bool:
names = [p for p in inspect.signature(fn).parameters if p != "self"]
return 0 <= idx < len(names) Prevention
- Check `inspect.signature(fn).parameters` before signature inference.
- Keep predict signatures in the canonical (self, input[, params]) form expected by your flavor.
- Re-run signature inference tests after refactoring predict functions.
When it happens
Trigger: Calling `mlflow.models.infer_signature` / `save_model` (or `_infer_signature_from_type_hints`) on a function whose predict signature has fewer non-self arguments than the configured `input_arg_index`, e.g. `def predict(self, x)` with input_arg_index=1, or a zero-argument predict function.
Common situations: Wrapping a model whose predict method takes only one input while MLflow's flavor expects (context, input) or (input, params) style signatures; typos when passing `input_arg_index` through custom flavor code; refactoring a predict function to remove arguments without updating signature inference config.
Related errors
- INVALID_PARAMETER_VALUE
- Either `func` or `parameters` must be provided.
- Failed to infer signature from type hint: {e.message}
- Message must be either a dict or a Message object, but got:
- Invalid content type. Must be either a string or a list, but
AI-assisted analysis of mlflow/mlflow@6a27f2decc (2026-08-29).
Data as JSON: /api/errors/6ac9203d10b6a5ed.
Report an issue: GitHub.