dotnet/machinelearning · error · ArgumentException
Provided {columnPurpose} column '{columnName}' was of type {
Error message
Provided {columnPurpose} column '{columnName}' was of type {itemType}, but only types {string.Join(", ", allowedTypes)} are allowed. What it means
The multi-type branch of ValidateTrainDataColumn's type check: when the column's item type is not among the several allowedTypes, this ArgumentException lists the actual type and all allowed types. Same root cause as the single-type variant, just with a richer allowed set.
Source
Thrown at src/Microsoft.ML.AutoML/Utils/UserInputValidationUtil.cs:278
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)
{
minEditDistance = editDistance;
closestNamed = column.Name;
}
}View on GitHub (pinned to 7b76e69cf9)
Solutions
- Convert the column to one of the listed allowed types (ConvertType transform) before Execute.
- Correct the ColumnInformation entry to a column whose type matches the allowed list.
- Use AutoML's InferColumns/InferColumnInformation so column purposes and types are inferred consistently.
Example fix
// before
var colInfo = new ColumnInformation { LabelColumnName = "Date" }; // DateTime, task allows Single
// after
var typed = mlContext.Transforms.Conversion.ConvertType("Date", outputKind: DataKind.Single).Fit(trainData).Transform(trainData); Defensive patterns
Strategy: validation
Validate before calling
var itemType = trainData.Schema[labelCol].Type.GetItemType();
var allowed = new[] { NumberDataViewType.Single, /* task-specific types */ };
if (!allowed.Contains(itemType)) throw new InvalidOperationException($"{itemType} not allowed for label"); Try / catch
try { result = experiment.Execute(trainData, settings, columnInfo); }
catch (ArgumentException ex) when (ex.Message.Contains("only types")) { /* convert to one of the listed types */ } Prevention
- Consult the task's allowed label types (GetAllowedLabelTypes logic) up front
- Use ConvertType to normalize label columns
- Prefer inferred ColumnInformation over manual entry
When it happens
Trigger: Designating a label column whose item type isn't in the task's allowed set (e.g. classification allows Single and NumberDataViewType key types — a Double or DateTime label fails).
Common situations: DateTime or Double labels for a task expecting Single/keys; label loaded as string for multiclass that requires KeyType; wrong column designated 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
- Provided {columnPurpose} column '{columnName}' was of type {
- Provided {columnPurpose} column '{columnName}' not found in
- Expected either {0} or {1} to be provided
- Cannot cast elements of column '{0}' type of {1} to type {2}
- Expected value to be of type {0}
AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11).
Data as JSON: /api/errors/e4a0edf61c23081d.
Report an issue: GitHub.