{"record":{"id":"ed98b3ae5dd150fc","repo":"dotnet/machinelearning","slug":"provided-columnpurpose-column-columnname-was","errorCode":null,"errorMessage":"Provided {columnPurpose} column '{columnName}' was of type {itemType}, but only type {allowedTypes.First()} is allowed.","messagePattern":"Provided (.+?) column '(.+?)' was of type (.+?), but only type (.+?) is allowed\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.AutoML/Utils/UserInputValidationUtil.cs","lineNumber":273,"sourceCode":"                if (closestNamed != string.Empty)\n                {\n                    exceptionMessage += $\" Did you mean '{closestNamed}'.\";\n                }\n\n                throw new ArgumentException(exceptionMessage);\n            }\n\n            if (allowedTypes == null)\n            {\n                return;\n            }\n            var column = nullableColumn.Value;\n            var itemType = column.Type.GetItemType();\n            if (!allowedTypes.Contains(itemType))\n            {\n                if (allowedTypes.Count() == 1)\n                {\n                    throw new ArgumentException($\"Provided {columnPurpose} column '{columnName}' was of type {itemType}, \" +\n                        $\"but only type {allowedTypes.First()} is allowed.\");\n                }\n                else\n                {\n                    throw new ArgumentException($\"Provided {columnPurpose} column '{columnName}' was of type {itemType}, \" +\n                        $\"but only types {string.Join(\", \", allowedTypes)} are allowed.\");\n                }\n            }\n        }\n\n        private static string ClosestNamed(IDataView trainData, string columnName, int maxAllowableEditDistance = int.MaxValue)\n        {\n            var minEditDistance = int.MaxValue;\n            var closestNamed = string.Empty;\n            foreach (var column in trainData.Schema)\n            {\n                var editDistance = StringEditDistance.GetLevenshteinDistance(column.Name, columnName);\n                if (editDistance < minEditDistance)","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.AutoML/Utils/UserInputValidationUtil.cs#L255-L291","documentation":"When an allowedTypes list is supplied for a purpose-designated column, ValidateTrainDataColumn enforces the item type. If the column's item type is not in the set and exactly one type is allowed, this ArgumentException is thrown naming both the actual and the only permitted type.","triggerScenarios":"Designating a label column with wrong data type for the task — e.g. a string label for regression (only Single allowed per GetAllowedLabelTypes), or a bool column where Single is required.","commonSituations":"Numeric-looking labels stored as strings in the CSV; passing a label key-typed column where Single is required; wrong column picked as label.","solutions":["Convert the column to the required type before Execute, e.g. mlContext.Data.Conversion.ConvertType or a CustomMapping.","Fix ColumnInformation to point at the correctly-typed column.","Change the task type if the label type is intentional (e.g. classification instead of regression)."],"exampleFix":"// before\nvar colInfo = new ColumnInformation { LabelColumnName = \"Label\" }; // Label is string\ncontext.AutoML(settings).Execute(trainData, colInfo); // regression task\n// after\nvar typed = mlContext.Transforms.Conversion.ConvertType(\"Label\", outputKind: DataKind.Single).Fit(trainData).Transform(trainData);","handlingStrategy":"validation","validationCode":"var itemType = trainData.Schema[columnInfo.LabelColumnName].Type.GetItemType();\nif (!allowedTypes.Contains(itemType))\n    trainData = mlContext.Transforms.Conversion.ConvertType(labelCol, outputKind: DataKind.Single).Fit(trainData).Transform(trainData);","typeGuard":null,"tryCatchPattern":"try { result = experiment.Execute(trainData, settings, columnInfo); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"only type\")) { /* convert label type and retry */ }","preventionTips":["Check label column item type against task requirements before Execute","Load numeric labels as numeric, not string","Match task kind (regression vs classification) to label type"],"tags":["type-mismatch","column","validation"],"backgroundTag":"type-mismatch","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}