{"record":{"id":"fc5410ed654ea550","repo":"dotnet/machinelearning","slug":"training-data-and-validation-data-schemas-do-not-m","errorCode":null,"errorMessage":"Training data and validation data schemas do not match. Train data has '{trainData.Schema.Count}' columns,and validation data has '{validationData.Schema.Count}' columns.","messagePattern":"Training data and validation data schemas do not match\\. Train data has '(.+?)' columns,and validation data has '(.+?)' columns\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.AutoML/Utils/UserInputValidationUtil.cs","lineNumber":200,"sourceCode":"        }\n\n        private static void ValidateValidationData(IDataView trainData, IDataView validationData)\n        {\n            if (validationData == null)\n            {\n                return;\n            }\n\n            if (DatasetDimensionsUtil.IsDataViewEmpty(validationData))\n            {\n                throw new ArgumentException(\"Validation data has 0 rows\", nameof(validationData));\n            }\n\n            const string schemaMismatchError = \"Training data and validation data schemas do not match.\";\n\n            if (trainData.Schema.Count(c => !c.IsHidden) != validationData.Schema.Count(c => !c.IsHidden))\n            {\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                }","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.AutoML/Utils/UserInputValidationUtil.cs#L182-L218","documentation":"AutoML requires validation data to be schema-compatible with training data. This ArgumentException is thrown when the counts of non-hidden columns differ between trainData and validationData, with both counts embedded in the message.","triggerScenarios":"Calling Execute with validationData whose schema has a different number of visible columns than trainData — e.g. validation file lacks a column, has extra columns, or was loaded with different settings (header/drop-options).","commonSituations":"Validation CSV missing a column due to schema drift upstream; one file has header row and the other does not; columns dropped in one loader but not the other.","solutions":["Compare the two schemas and align columns before calling Execute (add/remove columns).","Load both files with the same TextLoader.Options so column sets match.","Use InferColumns on the training file and reuse the resulting ColumnInformation/loader settings for validation data."],"exampleFix":"// before\nvar valData = mlContext.Data.LoadFromTextFile<Row>(\"val.csv\", hasHeader: false); // one column short\n// after\nvar valData = mlContext.Data.LoadFromTextFile<Row>(\"val.csv\", hasHeader: true);\nif (valData.Schema.Count(c => !c.IsHidden) != trainData.Schema.Count(c => !c.IsHidden))\n    throw new InvalidOperationException(\"align validation schema before Execute\");","handlingStrategy":"validation","validationCode":"var t = trainData.Schema.Count(c => !c.IsHidden);\nvar v = validationData.Schema.Count(c => !c.IsHidden);\nif (t != v) throw new InvalidOperationException($\"column count mismatch: {t} vs {v}\");","typeGuard":null,"tryCatchPattern":"try { result = experiment.Execute(trainData, validationData, ...); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"schemas do not match\")) { /* re-align schema and retry */ }","preventionTips":["Load train and validation with the same loader/schema options","Run schema drift checks in your data pipeline","Infer loader settings once from the training file and reuse them"],"tags":["schema","idataview","validation"],"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"}