Fixed: "UserWarning: Add type hints to the `predict` method" in MLflow
Logging a small custom MLflow model printed UserWarning: Add type hints to the predict method to enable data validation and automatic signature inference during model logging, twice, with an integer-columns hint in between. MLflow uses the type hints of a PythonModel's predict method to check its input and to write its signature. Typing predict as list[float] in and out, as MLflow's guide shows, fixed both warnings.
What I Was Doing
For the MLflow series, I needed a custom model, one with my own predict method, to try out the model server's request timeout. Logging my first version printed this warning, so here it is with the smallest model that shows it: a model that doubles each number it gets. It's a script, doubler.py, that MLflow logs from its code:
import mlflow
class Doubler(mlflow.pyfunc.PythonModel):
def predict(self, context, model_input):
return [number * 2 for number in model_input]
mlflow.models.set_model(Doubler())
And log_doubler.py, which logs it to a local tracking server, with two numbers as the input example:
import mlflow
mlflow.set_tracking_uri("http://127.0.0.1:8080")
mlflow.set_experiment("type-hints-fix")
with mlflow.start_run():
info = mlflow.pyfunc.log_model(name="model", python_model="doubler.py", input_example=[1.0, 2.0])
print("Model URI:", info.model_uri)
uv run python log_doubler.py
This is a uv project with MLflow 3.18.0 on Python 3.15.2.
What I Expected
The model's URI, with no warnings.
What I Got
/Users/you/source/serving-demo/.venv/lib/python3.15/site-packages/mlflow/pyfunc/utils/data_validation.py:187: UserWarning: Add type hints to the `predict` method to enable data validation and automatic signature inference during model logging. Check https://mlflow.org/docs/latest/model/python_model.html#type-hint-usage-in-pythonmodel for more details.
color_warning(
2026/11/26 05:01:04 INFO mlflow.pyfunc: Inferring model signature from input example
/Users/you/source/serving-demo/.venv/lib/python3.15/site-packages/mlflow/types/utils.py:440: UserWarning: Hint: Inferred schema contains integer column(s). Integer columns in Python cannot represent missing values. ...
warnings.warn(
/Users/you/source/serving-demo/.venv/lib/python3.15/site-packages/mlflow/pyfunc/utils/data_validation.py:187: UserWarning: Add type hints to the `predict` method to enable data validation and automatic signature inference during model logging. Check https://mlflow.org/docs/latest/model/python_model.html#type-hint-usage-in-pythonmodel for more details.
color_warning(
Model URI: models:/m-d06ffc063610433b97a27bae9a900fd9

The model was logged, but with three warnings, and MLflow had to guess its signature from the input example: Inferring model signature from input example.
What I Checked
The link in the warning. It leads to "Type hint usage in PythonModel" in MLflow's custom Python model guide:
Starting from MLflow 2.20.0, type hints are now a valid way to define your model's interfaces. You can use type hints to define the input and output types of the model.
It lists what they bring: "Data validation: MLflow validates the input data based on the type hints defined in the model." and "Type hint inference: MLflow infers the input and output schema of the model based on the type hints defined in the model, and sets that inferred structure as the logged model signature."
Which hints are allowed. The same page: "Type hints used within the PythonModel's input signature must be of type list[...] because PythonModel's predict function expects batch input data." float is one of the supported element types.
My predict had no hints, so MLflow fell back to guessing the signature from the example, and that guess produced the integer-columns hint.
Why It Happens
When predict has no type hints, MLflow can't tell what the model takes or returns, so it can't check requests or write a signature from the code. It warns, at the point where it would have used them, and infers the signature from the input example instead, which is where the integer-columns hint came from.
The Fix
Type predict: a list of floats in, a list of floats out, in the form the guide shows, predict(self, model_input: list[...], params=None):
import mlflow
class Doubler(mlflow.pyfunc.PythonModel):
def predict(self, model_input: list[float], params=None) -> list[float]:
return [number * 2 for number in model_input]
mlflow.models.set_model(Doubler())
![The fixed doubler.py in a macOS-style code window: the Doubler class whose predict method takes model_input as list[float] and params=None and returns list[float], and set_model at the end.](https://strdewiridedevblogsprod.blob.core.windows.net/images/blog/ai/mlflow/fixes/2026/mlflow-type-hints-02-code.webp)
log_doubler.py stays the same.
After the Fix
uv run python log_doubler.py
2026/11/26 05:01:09 INFO mlflow.models.signature: Running the predict function to generate output based on input example
Model URI: models:/m-0cf35de373504f43aebfa87a19284c92

No warnings. MLflow took the signature from the hints and only ran predict on the example to check it.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
model_input: float instead of list[float] | Not a supported hint: the guide says input hints "must be of type list[...]" | list[float] |
Sending the typed model a dataframe_split request | 400: Request payload must be a dictionary with 'inputs' key when the model contains a valid type hint | Send {"inputs": [...]} |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
The model server answers Found keys in payload: dict_keys(['dataframe_split']) | A model with type hints reads only the inputs layout | Send {"inputs": [1.0, 2.0]}: How to Send inputs or instances to an MLflow Model Server |
Passing a Python object as python_model causes it to be serialized using CloudPickle | The model was logged as an object, not from a file | Fixed: Passing a Python object as python_model |
FAQ
Is the integer-columns hint a separate problem?
It came from MLflow guessing the signature from the example. With type hints there's nothing to guess, and it went away too. For a scikit-learn model, where it means something else, see Fixed: Hint: Inferred schema contains integer column(s).
Do I still need the input example?
It's still useful: MLflow runs predict on it to check that the model works, as the output shows, and saves it with the model.
Conclusion
A PythonModel without type hints made MLflow warn Add type hints to the predict method and guess the signature from the input example. With predict(self, model_input: list[float], params=None) -> list[float], MLflow took the signature from the hints, and the warnings were gone.
Additional Resources
- Custom Python models: type hint usage in PythonModel — the supported hints and what they do.
- Models From Code — logging a model from a script, as
doubler.pyis here. - mlflow.pyfunc.log_model — the call and its arguments.
