dotnet/machinelearning · critical · ArgumentException

Provided label column cannot be null

Error message

Provided label column cannot be null

What it means

Thrown by UserInputValidationUtil.ValidateLabelColumn when the label column name supplied to an AutoML API (experiment execution or column inference) is null. Every supervised AutoML task requires an identified label column, so a null name is rejected with an ArgumentException (note: not ArgumentNullException despite the null check).

Source

Thrown at src/Microsoft.ML.AutoML/Utils/UserInputValidationUtil.cs:160

            if (duplicateColName != null)
            {
                throw new ArgumentException($"Duplicate column name {duplicateColName} is present in two or more distinct properties of provided column information", nameof(columnInformation));
            }
        }

        private static void ValidateColumnInfoEnumerationProperty(IEnumerable<string> columns, string columnPurpose)
        {
            if (columns?.Contains(null) == true)
            {
                throw new ArgumentException($"Null column string was specified as {columnPurpose} in column information");
            }
        }

        private static void ValidateLabelColumn(string labelColumn)
        {
            if (labelColumn == null)
            {
                throw new ArgumentException("Provided label column cannot be null");
            }
        }

        private static void ValidatePath(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path), "Provided path cannot be null");
            }

            var fileInfo = new FileInfo(path);

            if (!fileInfo.Exists)
            {
                throw new ArgumentException($"File '{path}' does not exist", nameof(path));
            }

            if (fileInfo.Length == 0)

View on GitHub (pinned to 7b76e69cf9)

Solutions

  1. Supply the actual label column name, e.g. experiment.Execute(data, nameof(ModelInput.Label), "A")
  2. Set ColumnInformation.LabelColumnName to a non-null column present in the schema
  3. Guard the label variable with a null/whitespace check before invoking the API

Example fix

// before
string labelCol = config.Label; // null when config lacks it
var result = experiment.Execute(trainData, labelCol, "A");

// after
string labelCol = config.Label ?? nameof(ModelInput.Label);
ArgumentException.ThrowIfNullOrEmpty(labelCol);
var result = experiment.Execute(trainData, labelCol, "A");
Defensive patterns

Strategy: type-guard

Validate before calling

if (string.IsNullOrEmpty(labelColumnName)) throw new InvalidOperationException("Label column name is required");

Type guard

static bool HasLabel(ColumnInformation c) => !string.IsNullOrEmpty(c?.LabelColumnName);

Try / catch

try { var r = experiment.Execute(data, label, "A"); }
catch (ArgumentException ex) when (ex.Message.Contains("label column cannot be null")) { /* prompt user / load default label column */ }

Prevention

When it happens

Trigger: Calling ValidateInferColumnsArgs or ValidateColumnInformation paths with labelColumn = null, e.g. experiment.Execute(trainData, null, ...) or ColumnInformation with LabelColumnName left null where required.

Common situations: Relying on a default label column name that does not exist so the variable resolved to null; passing the wrong property from a config object; constructing ColumnInformation without setting LabelColumnName for APIs that require it.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11). Data as JSON: /api/errors/7adee3c592c2c936. Report an issue: GitHub.