# Cleaning Messy CSVs With A Rules-First Prompt

> Make it list the rules it will apply before it touches a single row.

- **Author:** [Ananya Iyer (@ananya_iyer)](https://www.promptabide.com/ananya_iyer)
- **Published:** 2026-02-20
- **Updated:** 2026-08-22
- **Tags:** `data`, `etl`, `pandas`, `data-quality`
- **Views:** 1712
- **Likes:** 560

## Prompt

```
Handing over a messy export and saying "clean this" gets you a cleaned file and no idea what it decided. Dates silently reinterpreted, a whole column dropped because it looked empty in the first 50 rows.

Two-step it:

"Here are the first 200 rows. Do not transform anything yet. List every data quality problem you can see and the rule you would apply for each. Flag any rule where the right choice is ambiguous."

Read the list, correct the two rules that are wrong, then:

"Apply those rules. Output the transformation script, not the transformed data, plus a count of rows affected per rule."

Getting the **script** rather than the data is the important part — it is reviewable, re-runnable, and works on the full 4M rows rather than the sample.
```

## Output

*Produced by Claude · claude-sonnet-4.*

```
Problems found:
1. `signup_date` mixes DD/MM/YYYY and YYYY-MM-DD. AMBIGUOUS: 03/04/2024 could be either. Rule: parse ISO first, treat the rest as DD/MM, flag rows where day <= 12.
2. `country` has "UK", "U.K.", "United Kingdom". Rule: map to ISO-3166 alpha-2.
3. `revenue` has 412 empty strings. AMBIGUOUS: empty vs zero. Rule: NULL, not 0.
```

---

Canonical HTML: https://www.promptabide.com/bides/cleaning-csv-rules-first-ananya-iyer-2
Agent guide: https://www.promptabide.com/llms.txt · https://www.promptabide.com/agent-instructions.md
Sitemap: https://www.promptabide.com/sitemap.xml
