{"record":{"id":"1fb605d0940a91d8","repo":"mlflow/mlflow","slug":"the-input-column-name-is-required-by-the-model","errorCode":null,"errorMessage":"The input column '{name}' is required by the model signature but missing from the input data.","messagePattern":"The input column '(.+?)' is required by the model signature but missing from the input data\\.","errorType":"exception","errorClass":"MlflowException","httpStatus":null,"severity":"error","filePath":"mlflow/models/utils.py","lineNumber":977,"sourceCode":"        # Otherwise, the schema is not valid.\n        else:\n            new_pf_input[x] = pd.Series(\n                [_enforce_type(obj, input_types[i]) for obj in pf_input[x]], name=x\n            )\n    return pd.DataFrame(new_pf_input)\n\n\ndef _enforce_named_col_schema(pf_input: pd.DataFrame, input_schema: Schema):\n    \"\"\"Enforce the input columns conform to the model's column-based signature.\"\"\"\n    input_names = input_schema.input_names()\n    input_dict = input_schema.input_dict()\n    new_pf_input = {}\n    for name in input_names:\n        input_type = input_dict[name].type\n        required = input_dict[name].required\n        if name not in pf_input:\n            if required:\n                raise MlflowException(\n                    f\"The input column '{name}' is required by the model \"\n                    \"signature but missing from the input data.\"\n                )\n            else:\n                continue\n        if isinstance(input_type, DataType):\n            new_pf_input[name] = _enforce_mlflow_datatype(name, pf_input[name], input_type)\n        # If the input_type is objects/arrays/maps, we assume pf_input must be a pandas DataFrame.\n        # Otherwise, the schema is not valid.\n        else:\n            new_pf_input[name] = pd.Series(\n                [_enforce_type(obj, input_type, required) for obj in pf_input[name]], name=name\n            )\n    return pd.DataFrame(new_pf_input)\n\n\ndef _reshape_and_cast_pandas_column_values(name, pd_series, tensor_spec):\n    if tensor_spec.shape[0] != -1 or -1 in tensor_spec.shape[1:]:","sourceCodeStart":959,"sourceCodeEnd":995,"githubUrl":"https://github.com/mlflow/mlflow/blob/6a27f2decc0b76eb1b54af31849784addb357dbc/mlflow/models/utils.py#L959-L995","documentation":"In `_enforce_named_col_schema`, MLflow checks each column declared in the model's (named-column) signature against the input DataFrame. A column marked `required=True` in the signature is absent from the input data, so enforcement fails with this plain MlflowException. This ensures inference inputs match the schema the model was trained/logged with.","triggerScenarios":"Calling `model.predict(df)` (or `mlflow.pyfunc`/spark UDF paths via `_enforce_pyspark_dataframe_schema`) with a DataFrame missing a required column; renaming or dropping a column upstream; selecting a subset of columns before predict.","commonSituations":"Feature pipelines that drop low-importance columns after model logging; ETL schema drift; loading a parquet/CSV where a column was renamed; train/serve skew where serving data omits a feature.","solutions":["Add the missing column to the input DataFrame before predict (fill with default/zero if the model was trained with it).","Rename the column to match the signature name exactly (case-sensitive).","If the column is genuinely optional, re-log the model with a signature where that column is `required=False` (or inferred as optional)."],"exampleFix":"// before\ndf = df[[\"a\", \"b\"]]\nmodel.predict(df)  # signature also requires 'c'\n// after\ndf[\"c\"] = 0  # or load the real value\nmodel.predict(df[[\"a\", \"b\", \"c\"]])","handlingStrategy":"validation","validationCode":"sig = model.metadata.signature\nrequired = [c.name for c in sig.inputs.inputs if getattr(c, 'required', True)]\nmissing = [c for c in required if c not in df.columns]\nif missing:\n    raise ValueError(f\"Missing required input columns: {missing}\")","typeGuard":null,"tryCatchPattern":"from mlflow.exceptions import MlflowException\ntry:\n    preds = model.predict(df)\nexcept MlflowException as e:\n    if \"required by the model signature but missing\" in str(e):\n        col = str(e).split(\"'\")[1]\n        df = df.assign(**{col: 0})\n        preds = model.predict(df)\n    else:\n        raise","preventionTips":["Validate DataFrame columns against the model signature in every serving entry point.","Lock feature pipelines with a schema contract (e.g. Great Expectations/pandera) matching the signature.","Avoid renaming/dropping columns after model logging without updating the signature."],"tags":["mlflow","schema","missing-column","dataframe"],"backgroundTag":"missing-required-column","analyzedSha":"6a27f2decc0b76eb1b54af31849784addb357dbc","analyzedAt":"2026-08-29T20:54:51.419Z","schemaVersion":2},"datasetVersion":"2026-08-29T22:17:34.462Z"}