dotnet/machinelearning · error · ArgumentException
Specified label column '{args.Label}' was not found.
Error message
Specified label column '{args.Label}' was not found. What it means
When the label is specified by name rather than index, ColumnTypeInference looks up an intermediate column matching args.Label among the inferred columns. If no column has that name it throws ArgumentException 'Specified label column ... was not found'. Unlike the generic validation error, this fires during type inference itself, usually because the file's actual headers differ from the configured label name.
Source
Thrown at src/Microsoft.ML.AutoML/ColumnInference/ColumnTypeInference.cs:397
private static IntermediateColumn GetAndValidateLabelColumn(Arguments args, IntermediateColumn[] cols)
{
IntermediateColumn labelColumn = null;
if (args.LabelColumnIndex != null)
{
// if label column index > inferred # of columns, throw error
if (args.LabelColumnIndex >= cols.Count())
{
throw new ArgumentOutOfRangeException(nameof(args.LabelColumnIndex), $"Label column index ({args.LabelColumnIndex}) is >= than # of inferred columns ({cols.Count()}).");
}
labelColumn = cols[args.LabelColumnIndex.Value];
}
else
{
labelColumn = cols.FirstOrDefault(c => c.Name == args.Label);
if (labelColumn == null)
{
throw new ArgumentException($"Specified label column '{args.Label}' was not found.");
}
}
return labelColumn;
}
public static TextLoader.Column[] GenerateLoaderColumns(Column[] columns)
{
var loaderColumns = new List<TextLoader.Column>();
foreach (var col in columns)
{
var loaderColumn = new TextLoader.Column(col.SuggestedName, col.ItemType.GetRawKind().ToDataKind(), col.ColumnIndex);
loaderColumns.Add(loaderColumn);
}
return loaderColumns.ToArray();
}
}
View on GitHub (pinned to 7b76e69cf9)
Solutions
- Compare the configured label name against the file's header row and correct the name (exact, case-sensitive match)
- Ensure the loader reads the header row (header=true / HasHeader) so column names come from the file
- Trim BOM/whitespace from header cells
- Run InferColumns with the corrected name, or specify the label by index as a workaround
Example fix
// before
var columnInfo = new ColumnInformation { LabelColumnName = "label" };
// after
var columnInfo = new ColumnInformation { LabelColumnName = "Label" }; // must match header exactly Defensive patterns
Strategy: validation
Validate before calling
bool hasLabel = dataView.Schema.Any(c => c.Name == labelName);
if (!hasLabel) throw new ArgumentException($"'{labelName}' not in schema"); Try / catch
try { var res = ColumnTypeInference.InferTypes(args); }
catch (ArgumentException ex) when (ex.Message.Contains("Specified label column"))
{ /* fix label name to match header */ } Prevention
- Ensure the loader reads the header row so names come from the file
- Match names exactly, case-sensitive
- Strip BOM/whitespace from the first header cell
When it happens
Trigger: Setting Label (or the experiment's LabelColumnName) to a name absent from the parsed file's headers; header row missing or misparsed so inferred column names are defaults (e.g. Column1...) instead of the expected ones; case or whitespace mismatch.
Common situations: Renamed columns in a newer data export; CSV loaded without a header option so names don't match; case-sensitivity mismatch; invisible BOM/whitespace in the first header cell.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Specified column {columnName} is not found in the dataset.
- can't add or update result that already save to csv
- IDatasetManager must be either ITrainTestDatasetManager or I
- OperationCanceledException
- Unable to split the file provided into multiple, consistent
AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11).
Data as JSON: /api/errors/ad4b9e5cf21ffd4d.
Report an issue: GitHub.