{"record":{"id":"5a59d872fa3f91bb","repo":"dotnet/machinelearning","slug":"training-data-and-validation-data-schemas-do-not-m-5a59d8","errorCode":null,"errorMessage":"Training data and validation data schemas do not match. Column '{trainCol.Name}' exists in train data, but not in validation data.","messagePattern":"Training data and validation data schemas do not match\\. Column '(.+?)' exists in train data, but not in validation data\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.AutoML/Utils/UserInputValidationUtil.cs","lineNumber":217,"sourceCode":"            {\n                throw new ArgumentException($\"{schemaMismatchError} Train data has '{trainData.Schema.Count}' columns,\" +\n                    $\"and validation data has '{validationData.Schema.Count}' columns.\", nameof(validationData));\n            }\n\n            // Validate that every active column in the train data corresponds to an active column in the validation data.\n            // (Indirectly, since we asserted above that the train and validation data have the same number of active columns, this also\n            // ensures the reverse -- that every active column in the validation data corresponds to an active column in the train data.)\n            foreach (var trainCol in trainData.Schema)\n            {\n                if (trainCol.IsHidden)\n                {\n                    continue;\n                }\n\n                var validCol = validationData.Schema.GetColumnOrNull(trainCol.Name);\n                if (validCol == null)\n                {\n                    throw new ArgumentException($\"{schemaMismatchError} Column '{trainCol.Name}' exists in train data, but not in validation data.\", nameof(validationData));\n                }\n\n                if (trainCol.Type != validCol.Value.Type && !trainCol.Type.Equals(validCol.Value.Type))\n                {\n                    throw new ArgumentException($\"{schemaMismatchError} Column '{trainCol.Name}' is of type {trainCol.Type} in train data, and type \" +\n                        $\"{validCol.Value.Type} in validation data.\", nameof(validationData));\n                }\n            }\n        }\n\n        private static void ValidateTrainDataColumns(IDataView trainData, IEnumerable<string> columnNames, string columnPurpose,\n            IEnumerable<DataViewType> allowedTypes = null)\n        {\n            if (columnNames == null)\n            {\n                return;\n            }\n","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.AutoML/Utils/UserInputValidationUtil.cs#L199-L235","documentation":"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.","triggerScenarios":"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.","commonSituations":"Schema drift between successive data exports; column renamed in feature engineering applied only to train data; hand-edited validation CSV header.","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."],"exampleFix":"// before\nvar valData = mlContext.Data.LoadFromTextFile(\"val.csv\", hasHeader: true); // header has \"label1\" vs train \"Label\"\n// after\nvar renamed = mlContext.Transforms.CopyColumns(\"label1\", \"Label\").Fit(valData).Transform(valData);","handlingStrategy":"validation","validationCode":"foreach (var col in trainData.Schema.Where(c => !c.IsHidden))\n    if (validationData.Schema.GetColumnOrNull(col.Name) == null)\n        throw new InvalidOperationException($\"validation data missing column {col.Name}\");","typeGuard":null,"tryCatchPattern":"try { result = experiment.Execute(trainData, validationData, ...); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"exists in train data, but not in validation data\")) { /* align column names */ }","preventionTips":["Derive validation data through the same transforms as training","Compare column names programmatically before Execute","Avoid hand-editing export headers"],"tags":["schema","column","idataview"],"backgroundTag":"schema-validation-failed","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"}