{"record":{"id":"77d8bfd3f02273f0","repo":"mlflow/mlflow","slug":"this-model-contains-a-column-based-signature-whic","errorCode":null,"errorMessage":"This model contains a column-based signature, which suggests a DataFrame input. There was an error casting the input data to a DataFrame: {e}","messagePattern":"This model contains a column-based signature, which suggests a DataFrame input\\. There was an error casting the input data to a DataFrame: (.+?)","errorType":"exception","errorClass":"MlflowException","httpStatus":null,"severity":"error","filePath":"mlflow/models/utils.py","lineNumber":1211,"sourceCode":"                    ):\n                        # Pandas DataFrames can't be constructed with embedded multi-dimensional\n                        # numpy arrays. Accordingly, we convert any multi-dimensional numpy\n                        # arrays to lists before constructing a DataFrame. This is safe because\n                        # ColSpec model signatures do not support array columns, so subsequent\n                        # validation logic will result in a clear \"incompatible input types\"\n                        # exception. This is preferable to a pandas DataFrame construction error\n                        pf_input = pd.DataFrame({\n                            key: (\n                                value.tolist()\n                                if (isinstance(value, np.ndarray) and value.ndim > 1)\n                                else value\n                            )\n                            for key, value in pf_input.items()\n                        })\n                    else:\n                        pf_input = pd.DataFrame(pf_input)\n                except Exception as e:\n                    raise MlflowException(\n                        \"This model contains a column-based signature, which suggests a DataFrame\"\n                        \" input. There was an error casting the input data to a DataFrame:\"\n                        f\" {e}\"\n                    )\n        elif isinstance(pf_input, (list, np.ndarray, pd.Series)):\n            pf_input = pd.DataFrame(pf_input)\n        elif HAS_PYSPARK and isinstance(pf_input, SparkDataFrame):\n            pf_input = pf_input.limit(10).toPandas()\n            for field in original_pf_input.schema.fields:\n                if isinstance(field.dataType, (StructType, ArrayType)):\n                    pf_input[field.name] = pf_input[field.name].apply(\n                        lambda row: convert_complex_types_pyspark_to_pandas(row, field.dataType)\n                    )\n        if not isinstance(pf_input, pd.DataFrame):\n            raise MlflowException(\n                f\"Expected input to be DataFrame. Found: {type(pf_input).__name__}\"\n            )\n","sourceCodeStart":1193,"sourceCodeEnd":1229,"githubUrl":"https://github.com/mlflow/mlflow/blob/6a27f2decc0b76eb1b54af31849784addb357dbc/mlflow/models/utils.py#L1193-L1229","documentation":"For column-based signatures, MLflow accepts dict, list, ndarray, or Series inputs and casts them to a pandas DataFrame. If that cast throws (e.g. dict values of unequal length or unhashable/mixed structures), the original exception is wrapped in this MlflowException.","triggerScenarios":"Predict/validate_schema with a dict of lists with different lengths, a list of dicts with inconsistent keys, or a jagged/ragged structure against a column-based signature where pd.DataFrame(pf_input) raises.","commonSituations":"Dict-of-arrays with mismatched lengths after partial data loading; list-of-dicts where some records miss keys but numpy conversion is attempted; passing dict of dicts which pandas cannot coerce as intended.","solutions":["Construct the DataFrame yourself first and fix the data (pad/truncate lists, align keys), then pass the DataFrame to predict.","Ensure dict values are equal-length lists/arrays/Series.","Normalize records with pd.DataFrame(records) explicitly and inspect the error before calling the model."],"exampleFix":"// before\nmodel.predict({\"a\": [1, 2, 3], \"b\": [4, 5]})  # unequal lengths\n\n// after\ndf = pd.DataFrame({\"a\": [1, 2, 3], \"b\": [4, 5, 6]})\nmodel.predict(df)","handlingStrategy":"validation","validationCode":"import pandas as pd\n\ndef as_safe_df(d):\n    if isinstance(d, dict):\n        lengths = {len(v) for v in d.values() if hasattr(v, \"__len__\")}\n        if len(lengths) > 1:\n            raise ValueError(f\"dict values have unequal lengths: {lengths}\")\n    return pd.DataFrame(d)  # raises locally with a clear traceback","typeGuard":"def is_df_castable(d):\n    return isinstance(d, (dict, list, np.ndarray, pd.Series, pd.DataFrame))","tryCatchPattern":"from mlflow.exceptions import MlflowException\ntry:\n    model.predict(data)\nexcept MlflowException as e:\n    if \"casting the input data to a DataFrame\" in str(e):\n        model.predict(pd.DataFrame(data))  # original pandas error surfaces\n    else:\n        raise","preventionTips":["Construct the DataFrame yourself so pandas errors are not wrapped","Ensure dict-of-lists values are equal length","Normalize list-of-dicts records to consistent keys"],"tags":["mlflow","column-signature","dataframe-cast","pandas"],"backgroundTag":"dataframe-conversion-failed","analyzedSha":"6a27f2decc0b76eb1b54af31849784addb357dbc","analyzedAt":"2026-08-29T20:54:51.419Z","schemaVersion":2},"datasetVersion":"2026-08-29T22:17:34.462Z"}