{"record":{"id":"4a8f20816bfaa693","repo":"dotnet/machinelearning","slug":"training-data-and-validation-data-schemas-do-not-m-4a8f20","errorCode":null,"errorMessage":"Training data and validation data schemas do not match. Column '{trainCol.Name}' is of type {trainCol.Type} in train data, and type {validCol.Value.Type} in validation data.","messagePattern":"Training data and validation data schemas do not match\\. Column '(.+?)' is of type (.+?) in train data, and type (.+?) in validation data\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.AutoML/Utils/UserInputValidationUtil.cs","lineNumber":222,"sourceCode":"            // 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\n            foreach (var columnName in columnNames)\n            {\n                ValidateTrainDataColumn(trainData, columnName, columnPurpose, allowedTypes);\n            }\n        }","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.AutoML/Utils/UserInputValidationUtil.cs#L204-L240","documentation":"This ArgumentException is thrown when a column present in both train and validation data has different DataViewTypes (e.g. Single vs String, or different key/vector types). The message reports both types so the mismatched column is easy to spot.","triggerScenarios":"Column typed as string in training file but numeric in validation file (or vice versa) because loaders inferred different types; KeyType/VectorType differing due to different loader options.","commonSituations":"Validation CSV has quoted numbers parsed as text; one file has missing values changing inferred type; TextLoader schema explicitly specified for one file but inferred for the other.","solutions":["Use one explicit TextLoader.Options/schema for both train and validation loads so types agree.","Convert validation column with ConvertTransform to the training column's type.","Inspect and compare `trainData.Schema[\"col\"].Type` vs validation before Execute."],"exampleFix":"// before\nvar valData = mlContext.Data.LoadFromTextFile(\"val.csv\", hasHeader: true); // inferred string for Amount\n// after\nvar opts = new TextLoader.Options { Columns = new[]{ new TextLoader.Column(\"Amount\", DataKind.Single, 3) } };\nvar valData = mlContext.Data.LoadFromTextFile(\"val.csv\", opts);","handlingStrategy":"validation","validationCode":"foreach (var col in trainData.Schema.Where(c => !c.IsHidden))\n{\n    var v = validationData.Schema.GetColumnOrNull(col.Name);\n    if (v != null && col.Type != v.Value.Type && !col.Type.Equals(v.Value.Type))\n        throw new InvalidOperationException($\"type mismatch on {col.Name}: {col.Type} vs {v.Value.Type}\");\n}","typeGuard":null,"tryCatchPattern":"try { result = experiment.Execute(trainData, validationData, ...); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"is of type\")) { /* convert types and retry */ }","preventionTips":["Share one explicit TextLoader schema between both loads","Beware type inference differences across files","Convert mismatched columns with Conversion.ConvertType"],"tags":["schema","type-mismatch","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"}