FoundationAgents/MetaGPT · error · ValueError

Content column not found in DataFrame.

Error message

Content column not found in DataFrame.

What it means

metagpt.document.validate_cols checks that the configured content column name exists in the pandas DataFrame before text is extracted from it (used by IndexableDocument.from_path for xlsx/csv/json data). If content_col (default 'content') is not among df.columns, ValueError 'Content column not found in DataFrame.' is raised.

Source

Thrown at metagpt/document.py:26

"""
from enum import Enum
from pathlib import Path
from typing import Optional, Union

import pandas as pd
from llama_index.core import Document, SimpleDirectoryReader
from llama_index.core.node_parser import SimpleNodeParser
from llama_index.readers.file import PDFReader
from pydantic import BaseModel, ConfigDict, Field
from tqdm import tqdm

from metagpt.logs import logger
from metagpt.repo_parser import RepoParser


def validate_cols(content_col: str, df: pd.DataFrame):
    if content_col not in df.columns:
        raise ValueError("Content column not found in DataFrame.")


def read_data(data_path: Path) -> Union[pd.DataFrame, list[Document]]:
    suffix = data_path.suffix
    if ".xlsx" == suffix:
        data = pd.read_excel(data_path)
    elif ".csv" == suffix:
        data = pd.read_csv(data_path)
    elif ".json" == suffix:
        data = pd.read_json(data_path)
    elif suffix in (".docx", ".doc"):
        data = SimpleDirectoryReader(input_files=[str(data_path)]).load_data()
    elif ".txt" == suffix:
        data = SimpleDirectoryReader(input_files=[str(data_path)]).load_data()
        node_parser = SimpleNodeParser.from_defaults(separator="\n", chunk_size=256, chunk_overlap=0)
        data = node_parser.get_nodes_from_documents(data)
    elif ".pdf" == suffix:
        data = PDFReader.load_data(str(data_path))

View on GitHub (pinned to 11cdf466d0)

Solutions

  1. Pass the actual column name: IndexableDocument.from_path(p, content_col='text').
  2. Rename the column in your data to 'content' before loading.
  3. Inspect df.columns first (pd.read_csv(p).columns) and strip whitespace/BOM from headers.

Example fix

# before
doc = IndexableDocument.from_path(Path('data.csv'))  # no 'content' column

# after
doc = IndexableDocument.from_path(Path('data.csv'), content_col='body')
Defensive patterns

Strategy: validation

Validate before calling

import pandas as pd
df = pd.read_csv(p, nrows=0)
if 'content' not in df.columns:
    content_col = next((c for c in ('text', 'body', 'page') if c in df.columns), None)
    assert content_col, f'no usable content column in {df.columns.tolist()}'
doc = IndexableDocument.from_path(p, content_col=content_col or 'content')

Type guard

def has_content_col(df: pd.DataFrame, col: str = 'content') -> bool:
    return col in set(df.columns)

Prevention

When it happens

Trigger: IndexableDocument.from_path('data.xlsx') where the sheet has no 'content' column (e.g. columns are 'text'/'body'/'page'), or from_path(..., content_col='txt') when the CSV header says 'text'.

Common situations: Feeding spreadsheets/CSV exports whose column names differ from MetaGPT's default; CSVs with BOM-mangled or whitespace-padded headers; users not realizing content_col must match their data's header exactly.

Related errors


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