{"record":{"id":"3b9ca400d9ba924b","repo":"FoundationAgents/MetaGPT","slug":"content-column-not-found-in-dataframe","errorCode":null,"errorMessage":"Content column not found in DataFrame.","messagePattern":"Content column not found in DataFrame\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"metagpt/document.py","lineNumber":26,"sourceCode":"\"\"\"\nfrom enum import Enum\nfrom pathlib import Path\nfrom typing import Optional, Union\n\nimport pandas as pd\nfrom llama_index.core import Document, SimpleDirectoryReader\nfrom llama_index.core.node_parser import SimpleNodeParser\nfrom llama_index.readers.file import PDFReader\nfrom pydantic import BaseModel, ConfigDict, Field\nfrom tqdm import tqdm\n\nfrom metagpt.logs import logger\nfrom metagpt.repo_parser import RepoParser\n\n\ndef validate_cols(content_col: str, df: pd.DataFrame):\n    if content_col not in df.columns:\n        raise ValueError(\"Content column not found in DataFrame.\")\n\n\ndef read_data(data_path: Path) -> Union[pd.DataFrame, list[Document]]:\n    suffix = data_path.suffix\n    if \".xlsx\" == suffix:\n        data = pd.read_excel(data_path)\n    elif \".csv\" == suffix:\n        data = pd.read_csv(data_path)\n    elif \".json\" == suffix:\n        data = pd.read_json(data_path)\n    elif suffix in (\".docx\", \".doc\"):\n        data = SimpleDirectoryReader(input_files=[str(data_path)]).load_data()\n    elif \".txt\" == suffix:\n        data = SimpleDirectoryReader(input_files=[str(data_path)]).load_data()\n        node_parser = SimpleNodeParser.from_defaults(separator=\"\\n\", chunk_size=256, chunk_overlap=0)\n        data = node_parser.get_nodes_from_documents(data)\n    elif \".pdf\" == suffix:\n        data = PDFReader.load_data(str(data_path))","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/document.py#L8-L44","documentation":"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.","triggerScenarios":"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'.","commonSituations":"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.","solutions":["Pass the actual column name: IndexableDocument.from_path(p, content_col='text').","Rename the column in your data to 'content' before loading.","Inspect df.columns first (pd.read_csv(p).columns) and strip whitespace/BOM from headers."],"exampleFix":"# before\ndoc = IndexableDocument.from_path(Path('data.csv'))  # no 'content' column\n\n# after\ndoc = IndexableDocument.from_path(Path('data.csv'), content_col='body')","handlingStrategy":"validation","validationCode":"import pandas as pd\ndf = pd.read_csv(p, nrows=0)\nif 'content' not in df.columns:\n    content_col = next((c for c in ('text', 'body', 'page') if c in df.columns), None)\n    assert content_col, f'no usable content column in {df.columns.tolist()}'\ndoc = IndexableDocument.from_path(p, content_col=content_col or 'content')","typeGuard":"def has_content_col(df: pd.DataFrame, col: str = 'content') -> bool:\n    return col in set(df.columns)","tryCatchPattern":null,"preventionTips":["Inspect df.columns before calling from_path with tabular data.","Strip whitespace/BOM from CSV headers during preprocessing.","Standardize on a 'content' column in your data pipeline."],"tags":["pandas","dataframe","rag","column-mapping"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}