{"record":{"id":"d903561bd4c46eca","repo":"mlflow/mlflow","slug":"cannot-get-input-dict-for-schema-without-names","errorCode":null,"errorMessage":"Cannot get input dict for schema without names.","messagePattern":"Cannot get input dict for schema without names\\.","errorType":"validation","errorClass":"MlflowException","httpStatus":null,"severity":"error","filePath":"mlflow/types/schema.py","lineNumber":1047,"sourceCode":"\n    def has_input_names(self) -> bool:\n        \"\"\"Return true iff this schema declares names, false otherwise.\"\"\"\n        return self.inputs and self.inputs[0].name is not None\n\n    def input_types(self) -> list[DataType | np.dtype | Array | Object]:\n        \"\"\"Get types for each column in the schema.\"\"\"\n        return [x.type for x in self.inputs]\n\n    def input_types_dict(self) -> dict[str, DataType | np.dtype | Array | Object]:\n        \"\"\"Maps column names to types, iff this schema declares names.\"\"\"\n        if not self.has_input_names():\n            raise MlflowException(\"Cannot get input types as a dict for schema without names.\")\n        return {x.name: x.type for x in self.inputs}\n\n    def input_dict(self) -> dict[str, ColSpec | TensorSpec]:\n        \"\"\"Maps column names to inputs, iff this schema declares names.\"\"\"\n        if not self.has_input_names():\n            raise MlflowException(\"Cannot get input dict for schema without names.\")\n        return {x.name: x for x in self.inputs}\n\n    def numpy_types(self) -> list[np.dtype]:\n        \"\"\"Convenience shortcut to get the datatypes as numpy types.\"\"\"\n        if self.is_tensor_spec():\n            return [x.type for x in self.inputs]\n        if all(isinstance(x.type, DataType) for x in self.inputs):\n            return [x.type.to_numpy() for x in self.inputs]\n        raise MlflowException(\n            \"Failed to get numpy types as some of the inputs types are not DataType.\"\n        )\n\n    def pandas_types(self) -> list[np.dtype]:\n        \"\"\"Convenience shortcut to get the datatypes as pandas types. Unsupported by TensorSpec.\"\"\"\n        if self.is_tensor_spec():\n            raise MlflowException(\"TensorSpec only supports numpy types, use numpy_types() instead\")\n        if all(isinstance(x.type, DataType) for x in self.inputs):\n            return [x.type.to_pandas() for x in self.inputs]","sourceCodeStart":1029,"sourceCodeEnd":1065,"githubUrl":"https://github.com/mlflow/mlflow/blob/6a27f2decc0b76eb1b54af31849784addb357dbc/mlflow/types/schema.py#L1029-L1065","documentation":"Schema.input_dict() maps column names to ColSpec/TensorSpec objects and requires named inputs. Calling it on an unnamed schema raises, since there is no name to index by.","triggerScenarios":"schema.input_dict() on a schema built from unnamed specs, e.g. Schema([TensorSpec(np.dtype(\"float64\"), (-1, 4))]).","commonSituations":"Looking up a spec by name in a signature inferred from a bare numpy array; a serving path that assumes named inputs but loads an unnamed-column model signature.","solutions":["Rebuild the schema with named ColSpec/TensorSpec entries","Guard with schema.has_input_names() and iterate schema.inputs directly otherwise","Access schema.inputs[0] for single unnamed-column schemas"],"exampleFix":"// before\nspec = schema.input_dict()[\"features\"]\n// after\nif schema.has_input_names():\n    spec = schema.input_dict()[\"features\"]\nelse:\n    spec = schema.inputs[0]","handlingStrategy":"try-catch","validationCode":"if not schema.has_input_names():\n    raise ValueError(\"input_dict requires a named schema\")","typeGuard":"def can_lookup_by_name(schema, name) -> bool:\n    return schema.has_input_names() and name in schema.input_names()","tryCatchPattern":"try:\n    spec = schema.input_dict()[\"features\"]\nexcept MlflowException:\n    spec = schema.inputs[0]  # unnamed single-column schema","preventionTips":["Guard name lookups with has_input_names() and input_names()","Rebuild unnamed schemas with names before dict access","Log the schema's input names when debugging signature mismatches"],"tags":["python","schema","api-misuse"],"backgroundTag":"missing-schema-input-names","analyzedSha":"6a27f2decc0b76eb1b54af31849784addb357dbc","analyzedAt":"2026-08-29T20:54:51.419Z","schemaVersion":2},"datasetVersion":"2026-08-29T22:17:34.462Z"}