Skip to main content
Prerequisites
  • Python 3.10 or higher
  • PraisonAI Agents package installed
  • PraisonAI Tools package installed
  • pandas package installed
The user points at a CSV; the agent reads, transforms, and writes results with CSV tools.

CSV Tools

Use CSV Tools to read, write, and manipulate CSV files with AI agents.
1

Install Dependencies

First, install the required packages:
2

Import Components

Import the necessary components:
3

Create Agent

Create a CSV processing agent:
4

Define Task

Define the CSV processing task:
5

Run Agent

Initialize and run the agent:

Understanding CSV Tools

What are CSV Tools?

CSV Tools provide CSV processing capabilities for AI agents:
  • File reading and writing
  • Data parsing
  • Column manipulation
  • Data filtering
  • Format conversion

Key Components

CSV Agent

Create specialized CSV agents:

CSV Task

Define CSV tasks:

Process Types

Sequential or parallel processing:

CSV Options

Customize CSV parameters:

Available Functions

Function Details

read_csv(filepath: str, encoding: str = ‘utf-8’, delimiter: str = ’,’, header: Union[int, List[int], None] = 0, usecols: Optional[List[str]] = None, dtype: Optional[Dict[str, str]] = None, parse_dates: Optional[List[str]] = None, na_values: Optional[List[str]] = None, nrows: Optional[int] = None)

Reads a CSV file with advanced options:
  • Supports multiple encodings (utf-8, ascii, etc.)
  • Configurable column delimiter
  • Flexible header row handling
  • Column selection and data type specification
  • Date parsing
  • Custom NA/NaN value handling
  • Row limit option

write_csv(filepath: str, data: List[Dict[str, Any]], encoding: str = ‘utf-8’, delimiter: str = ’,’, index: bool = False, header: bool = True, float_format: Optional[str] = None, date_format: Optional[str] = None, mode: str = ‘w’)

Writes data to a CSV file with formatting options:
  • Supports different encodings
  • Configurable delimiter
  • Optional row indices
  • Optional headers
  • Custom float and date formatting
  • Append mode support

merge_csv(files: List[str], output_file: str, how: str = ‘inner’, on: Optional[Union[str, List[str]]] = None, suffixes: Optional[tuple] = None)

Merges multiple CSV files with flexible join options:
  • Supports different join types (inner, outer, left, right)
  • Merge on single or multiple columns
  • Custom suffixes for overlapping columns
  • Automatic handling of column name conflicts

Dependencies

The CSV tools require the following Python packages:
  • pandas: For advanced CSV operations and data manipulation
These will be automatically installed when needed.

Example Agent Configuration

Error Handling

All functions include comprehensive error handling:
  • File not found errors
  • Permission errors
  • Encoding errors
  • Data format errors
  • Missing dependency errors
Errors are logged and returned in a consistent format:
  • Success cases return the expected data type
  • Error cases return a dict with an “error” key containing the error message

Examples

Basic CSV Processing Agent

Advanced CSV Processing with Multiple Agents

Best Practices

Configure agents with clear CSV focus:
Define specific CSV operations:

Common Patterns

CSV Processing Pipeline

Custom Tools

Build your own agent tools

Tools Overview

Browse PraisonAI tool documentation