dotnet/machinelearning · error · ArgumentException
Training data and validation data schemas do not match. Colu
Error message
Training data and validation data schemas do not match. Column '{trainCol.Name}' exists in train data, but not in validation data. What it means
After column-count checks, ValidateValidationData iterates training-schema columns and requires each to exist in validation data. This ArgumentException fires when a training column name is missing from the validation IDataView schema.
Source
Thrown at src/Microsoft.ML.AutoML/Utils/UserInputValidationUtil.cs:217
{
throw new ArgumentException($"{schemaMismatchError} Train data has '{trainData.Schema.Count}' columns," +
$"and validation data has '{validationData.Schema.Count}' columns.", nameof(validationData));
}
// Validate that every active column in the train data corresponds to an active column in the validation data.
// (Indirectly, since we asserted above that the train and validation data have the same number of active columns, this also
// ensures the reverse -- that every active column in the validation data corresponds to an active column in the train data.)
foreach (var trainCol in trainData.Schema)
{
if (trainCol.IsHidden)
{
continue;
}
var validCol = validationData.Schema.GetColumnOrNull(trainCol.Name);
if (validCol == null)
{
throw new ArgumentException($"{schemaMismatchError} Column '{trainCol.Name}' exists in train data, but not in validation data.", nameof(validationData));
}
if (trainCol.Type != validCol.Value.Type && !trainCol.Type.Equals(validCol.Value.Type))
{
throw new ArgumentException($"{schemaMismatchError} Column '{trainCol.Name}' is of type {trainCol.Type} in train data, and type " +
$"{validCol.Value.Type} in validation data.", nameof(validationData));
}
}
}
private static void ValidateTrainDataColumns(IDataView trainData, IEnumerable<string> columnNames, string columnPurpose,
IEnumerable<DataViewType> allowedTypes = null)
{
if (columnNames == null)
{
return;
}
View on GitHub (pinned to 7b76e69cf9)
Solutions
- Rename the validation column to match training data (e.g. CopyColumns transform).
- Regenerate validation data from the same pipeline as training data.
- Verify column names in both schemas with `schema.Select(c => c.Name)` before Execute.
Example fix
// before
var valData = mlContext.Data.LoadFromTextFile("val.csv", hasHeader: true); // header has "label1" vs train "Label"
// after
var renamed = mlContext.Transforms.CopyColumns("label1", "Label").Fit(valData).Transform(valData); Defensive patterns
Strategy: validation
Validate before calling
foreach (var col in trainData.Schema.Where(c => !c.IsHidden))
if (validationData.Schema.GetColumnOrNull(col.Name) == null)
throw new InvalidOperationException($"validation data missing column {col.Name}"); Try / catch
try { result = experiment.Execute(trainData, validationData, ...); }
catch (ArgumentException ex) when (ex.Message.Contains("exists in train data, but not in validation data")) { /* align column names */ } Prevention
- Derive validation data through the same transforms as training
- Compare column names programmatically before Execute
- Avoid hand-editing export headers
When it happens
Trigger: Validation data renamed a column, or the validation file/loader produced different column names (e.g. header misspelled, case differences not involved here since GetColumnOrNull matches by name), while counts coincidentally matched.
Common situations: Schema drift between successive data exports; column renamed in feature engineering applied only to train data; hand-edited validation CSV header.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Training data and validation data schemas do not match. Trai
- Training data and validation data schemas do not match. Colu
- Exception of type 'System.ArgumentException' was thrown.
- String.Format(Microsoft.Data.Strings.NotSupportedColumnType,
- String.Format(Microsoft.Data.Strings.VectorSubTypeNotSupport
AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11).
Data as JSON: /api/errors/5a59d872fa3f91bb.
Report an issue: GitHub.