Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:CrewAIInc CrewAI RAG CSV Loader

From Leeroopedia
Knowledge Sources
Domains RAG, Data_Loading
Last Updated 2026-02-11 00:00 GMT

Overview

Loads and parses CSV files from local paths or URLs into structured text format suitable for RAG ingestion.

Description

CSVLoader extends BaseLoader to handle CSV data from multiple sources. It reads content from local files (using UTF-8 encoding) or fetches from URLs via the shared load_from_url utility with appropriate CSV accept headers.

The _parse_csv() method uses Python's csv.DictReader to parse the content. It formats the output as structured text with a header line listing all column names separated by pipes, a visual separator, and then each row formatted as numbered entries with key-value pairs (e.g., "Row 1: name: Alice | age: 30"). Empty values are filtered out.

The returned LoaderResult includes metadata about the format, column names, and row count. Parse errors are handled gracefully by returning the raw content with error information in the metadata.

Usage

Import CSVLoader when you need to explicitly load CSV data. It is typically instantiated automatically by the DataType.CSV registry when the RAG system detects CSV content.

Code Reference

Source Location

  • Repository: CrewAI
  • File: lib/crewai-tools/src/crewai_tools/rag/loaders/csv_loader.py
  • Lines: 1-63

Signature

class CSVLoader(BaseLoader):
    def load(self, source_content: SourceContent, **kwargs) -> LoaderResult: ...

Import

from crewai_tools.rag.loaders.csv_loader import CSVLoader

I/O Contract

Inputs

Name Type Required Description
source_content SourceContent Yes Wraps a CSV file path, URL, or raw CSV string
**kwargs Any No Additional keyword arguments passed to URL loading

Outputs

Name Type Description
return LoaderResult Contains formatted text content, source reference, metadata (format, columns, rows), and doc_id

Usage Examples

Basic Usage

from crewai_tools.rag.loaders.csv_loader import CSVLoader
from crewai_tools.rag.source_content import SourceContent

loader = CSVLoader()

# Load from a local file
source = SourceContent("/path/to/data.csv")
result = loader.load(source)
print(result.content)
# Output:
# Headers: name | age | city
# --------------------------------------------------
# Row 1: name: Alice | age: 30 | city: New York

# Load from a URL
source = SourceContent("https://example.com/data.csv")
result = loader.load(source)
print(result.metadata)
# {'format': 'csv', 'columns': ['name', 'age', 'city'], 'rows': 10}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment