dotnet/machinelearning · error · ArgumentException

Provided {columnPurpose} column '{columnName}' was of type {

Error message

Provided {columnPurpose} column '{columnName}' was of type {itemType}, but only type {allowedTypes.First()} is allowed.

What it means

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.

Source

Thrown at src/Microsoft.ML.AutoML/Utils/UserInputValidationUtil.cs:273

                if (closestNamed != string.Empty)
                {
                    exceptionMessage += $" Did you mean '{closestNamed}'.";
                }

                throw new ArgumentException(exceptionMessage);
            }

            if (allowedTypes == null)
            {
                return;
            }
            var column = nullableColumn.Value;
            var itemType = column.Type.GetItemType();
            if (!allowedTypes.Contains(itemType))
            {
                if (allowedTypes.Count() == 1)
                {
                    throw new ArgumentException($"Provided {columnPurpose} column '{columnName}' was of type {itemType}, " +
                        $"but only type {allowedTypes.First()} is allowed.");
                }
                else
                {
                    throw new ArgumentException($"Provided {columnPurpose} column '{columnName}' was of type {itemType}, " +
                        $"but only types {string.Join(", ", allowedTypes)} are allowed.");
                }
            }
        }

        private static string ClosestNamed(IDataView trainData, string columnName, int maxAllowableEditDistance = int.MaxValue)
        {
            var minEditDistance = int.MaxValue;
            var closestNamed = string.Empty;
            foreach (var column in trainData.Schema)
            {
                var editDistance = StringEditDistance.GetLevenshteinDistance(column.Name, columnName);
                if (editDistance < minEditDistance)

View on GitHub (pinned to 7b76e69cf9)

Solutions

  1. Convert the column to the required type before Execute, e.g. mlContext.Data.Conversion.ConvertType or a CustomMapping.
  2. Fix ColumnInformation to point at the correctly-typed column.
  3. Change the task type if the label type is intentional (e.g. classification instead of regression).

Example fix

// before
var colInfo = new ColumnInformation { LabelColumnName = "Label" }; // Label is string
context.AutoML(settings).Execute(trainData, colInfo); // regression task
// after
var typed = mlContext.Transforms.Conversion.ConvertType("Label", outputKind: DataKind.Single).Fit(trainData).Transform(trainData);
Defensive patterns

Strategy: validation

Validate before calling

var itemType = trainData.Schema[columnInfo.LabelColumnName].Type.GetItemType();
if (!allowedTypes.Contains(itemType))
    trainData = mlContext.Transforms.Conversion.ConvertType(labelCol, outputKind: DataKind.Single).Fit(trainData).Transform(trainData);

Try / catch

try { result = experiment.Execute(trainData, settings, columnInfo); }
catch (ArgumentException ex) when (ex.Message.Contains("only type")) { /* convert label type and retry */ }

Prevention

When it happens

Trigger: 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.

Common situations: Numeric-looking labels stored as strings in the CSV; passing a label key-typed column where Single is required; wrong column picked as label.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11). Data as JSON: /api/errors/ed98b3ae5dd150fc. Report an issue: GitHub.