Skip to main content

data-cleaner-agent

Clean a messy CSV with an agentic workflow. An LLM decides which cleaning steps the data needs, and tested Python functions do the actual work. The model plans the cleanup, it never touches your data values, so nothing gets hallucinated or silently rewritten.

Works offline out of the box (no API key). Can be driven by an LLM, and other AI agents can call it as an MCP tool.

Before / after

Full Name , Country, Signup Date, Amount Paid          full_name    country  signup_date  amount_paid
 Alice  ,Netherlands,2023-01-05,"€1.200,50"                Alice  Netherlands   2023-01-05       1200.5
Bob,nederland,05/01/2023,"$900"              ─────▶          Bob  Netherlands   2023-01-05        900.0
 Alice  ,NL,2023-01-05,"€1.200,50"                         Carol      Germany   2023-02-10       1000.0
Carol , Germany ,2023-02-10,1000                             Dan      Belgium   2023-03-01        750.0
Dan,belgie,2023/03/01,"€ 750,00"

In one pass it fixed the headers, trimmed whitespace, parsed three different date formats to ISO, turned €1.200,50 / $900 / € 750,00 into numbers, standardized the country names, and dropped the duplicate Alice row.

Install & run

pip install agentic-csv-cleaner

clean-csv messy.csv cleaned.csv       # clean a file
clean-csv messy.csv                   # or just print the result

No API key needed. The default planner is a set of offline heuristics.

The idea

An "agentic workflow" is just software with a few parts:

   look at the data   ->   planner picks the steps   ->   run the steps   ->   report
                           (rules, or an LLM)             (tested code)

The decision that makes it safe to trust:

The planner decides which tool runs on which column. The tools do the transformation. A language model is good at judgment ("this column looks like money") and bad at being a reliable calculator. So the LLM only ever picks operations from a fixed set. It never reads a value and writes back a "cleaned" one, which is where LLM data-cleaning usually goes wrong.

Two planners, one loop

Planner What it is Needs
RuleBasedPlanner Offline heuristics from a quick data profile. The default. nothing
LLMPlanner Sends the profile + tool list to an LLM, gets back a JSON plan. pip install "agentic-csv-cleaner[llm]" + ANTHROPIC_API_KEY

Both return the same list of steps, so the loop is identical. You swap the brain, not the plumbing.

The log reports what each step actually did, including where a conversion could not produce a clean result (unparseable numbers/dates, unmapped categories), so a clean parse is distinguishable from a confident guess.

Use it from other code or agents

from cleaner.api import clean_csv_text

result = clean_csv_text(open("messy.csv").read())
print(result["cleaned_csv"])
print(result["steps"])

As an MCP tool

Other AI agents (Claude Desktop, or any MCP client) can call the cleaner as a tool, so they can clean a CSV properly instead of reformatting it token by token in the prompt:

pip install "agentic-csv-cleaner[mcp]"
python -m cleaner.mcp_server

This exposes one tool, clean_csv, that takes CSV text and returns the cleaned CSV plus the steps.

What's in the box

cleaner/tools.py holds the transformations: snake_case_headers, strip_whitespace, coerce_numeric, standardize_dates, standardize_categorical, drop_duplicate_rows.

Take standardize_dates. 2023-01-05 (year first, month in the middle) and 05/01/2023 (day first) need opposite parsing rules, and one global setting corrupts one or the other, so the tool decides per value. Mixed dates are genuinely ambiguous, and this handles them explicitly instead of guessing.

Tests

python -m unittest discover -s tests

License

MIT.

Release files for agentic-csv-cleaner 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for agentic-csv-cleaner 0.1.3
File Size Uploaded
agentic_csv_cleaner-0.1.3.tar.gz 11.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for agentic-csv-cleaner 0.1.3
File Interpreter ABI Platform
agentic_csv_cleaner-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 25.7 kB

Release files / agentic_csv_cleaner-0.1.3.tar.gz

Download URL agentic_csv_cleaner-0.1.3.tar.gz
Size 11.9 kB
Tags Source
SHA-256 checksum
How to use checksums
2b13548c4a5a5cd57536aadfa9554a863b013c6713d7a422609d4348a5d52256
BLAKE2b-256 checksum
How to use checksums
a3cf0c0477e66da4a760464a004d87babc5159e1231c6a28920612841c615af5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / agentic_csv_cleaner-0.1.3-py3-none-any.whl

Download URL agentic_csv_cleaner-0.1.3-py3-none-any.whl
Size 13.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bcec9b829b043c40ac4359150333130e6ebe8d570e4a91ad1a27faf2e1b8b627
BLAKE2b-256 checksum
How to use checksums
bbaf33583f484293d1e80a8ecb2a8910ca0824f5eb0716aef6c5e3050a2b2df1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page