FoundationAgents/MetaGPT · error · ValueError

Target column not provided

Error message

Target column not provided

What it means

Raised by ExpDataset.split_and_save when target_col is falsy (None or empty string). Splits need the target column to emit the *_wo_target.csv and *_target.csv side files used by SELA evaluation, so train/dev/test cannot be saved without it.

Source

Thrown at metagpt/ext/sela/data/dataset.py:319

        with open(Path(self.dataset_dir, self.name, "dataset_info.json"), "w", encoding="utf-8") as file:
            # utf-8 encoding is required
            json.dump(dataset_info, file, indent=4, ensure_ascii=False)

    def save_split_datasets(self, df, split, target_col=None):
        path = Path(self.dataset_dir, self.name)
        df.to_csv(Path(path, f"split_{split}.csv"), index=False)
        if target_col:
            df_wo_target = df.drop(columns=[target_col])
            df_wo_target.to_csv(Path(path, f"split_{split}_wo_target.csv"), index=False)
            df_target = df[[target_col]].copy()
            if target_col != "target":
                df_target["target"] = df_target[target_col]
                df_target = df_target.drop(columns=[target_col])
            df_target.to_csv(Path(path, f"split_{split}_target.csv"), index=False)

    def split_and_save(self, df, target_col, test_df=None):
        if not target_col:
            raise ValueError("Target column not provided")
        if test_df is None:
            train, test = train_test_split(df, test_size=1 - TRAIN_TEST_SPLIT, random_state=SEED)
        else:
            train = df
            test = test_df
        train, dev = train_test_split(train, test_size=1 - TRAIN_DEV_SPLIT, random_state=SEED)
        self.save_split_datasets(train, "train")
        self.save_split_datasets(dev, "dev", target_col)
        self.save_split_datasets(test, "test", target_col)


class OpenMLExpDataset(ExpDataset):
    def __init__(self, name, dataset_dir, dataset_id, **kwargs):
        self.dataset_id = dataset_id
        self.dataset = openml.datasets.get_dataset(
            self.dataset_id, download_data=False, download_qualities=False, download_features_meta_data=True
        )
        self.name = self.dataset.name

View on GitHub (pinned to 11cdf466d0)

Solutions

  1. Provide the correct target column name (string) for the dataset
  2. Add 'target_col' to the dataset's entry in datasets.yaml so save_dataset receives it
  3. Verify the column name exists in the raw train.csv header

Example fix

# before
dataset.split_and_save(df, target_col=None)

# after
dataset.split_and_save(df, target_col="class")
Defensive patterns

Strategy: validation

Validate before calling

assert target_col, "target column required"
assert target_col in df.columns

Type guard

def has_target_col(target_col) -> bool:
    return isinstance(target_col, str) and bool(target_col)

Prevention

When it happens

Trigger: Calling split_and_save(df, None) or save_dataset(target_col=None), typically when the dataset entry in datasets.yaml lacks a target_col.

Common situations: Custom dataset registered in config without target_col; programmatic use of ExpDataset where the caller forgot to pass the column.

Related errors


AI-assisted analysis of FoundationAgents/MetaGPT@11cdf466d0 (2026-08-14). Data as JSON: /api/errors/7262bc278e6b03a2. Report an issue: GitHub.