Data Cleaning Loop
Clean messy datasets with repeatable validation and artifact outputs.
What this Loop Engineering template does
Produce a clean dataset and a reproducible cleaning script, documenting every transformation.
Never overwrite the raw data. Label any imputed values. Keep the script reproducible.
When to use it
When not to use it
Validation checks
Boundaries & stop rule
Copy the loop prompt
/goal Produce a clean dataset and a reproducible cleaning script, documenting every transformation.Task type: Data CleaningTarget tool: Generic AgentWork toward this goal until all validation checks pass or the stop rule is reached.Design hypothesis:This data cleaning loop can produce a safer result if the scope stays narrow, validation is explicit, and a checker can reject shortcut work.Smallest useful run:Run one bounded pass on the newest relevant signal before expanding scope or adding a schedule.Loop cycle:1. Discovery — Read the latest signal for this template before acting: CI output, issue detail, review comment, dataset report, or content brief.2. Handoff — Hand the work to one agent in an isolated branch, worktree, or clearly scoped session. Keep final approval with a human.3. Verification — Use an independent review pass to confirm the result, inspect the diff or artifact, and reject shortcut work.4. Persistence — Save a short run note with the signal reviewed, actions taken, validation result, and next recommended step.5. Scheduling — Run manually until the loop is reliable; only then consider a scheduled or event-triggered run.Context:Never overwrite the raw data. Label any imputed values. Keep the script reproducible.Validation:Missing values are reportedSchema is documentedCleaning script is reproducibleFinal dataset passes validation checksValidation evidence:Record the original signal, checks run, final result, changed files or artifacts, and any checker rejection.Independent checker:Use an independent review pass to confirm the result, inspect the diff or artifact, and reject shortcut work.Boundaries:Do not silently delete rowsDo not overwrite raw dataDo not invent missing values without labeling imputationStop rule:Stop when the cleaned dataset passes validation and the script reproduces it.Maximum iterations: 4Budget:Example only: stop before exceeding the agreed per-run token budget.Human approval:Required before merge, deploy, delete, purchase, or external communication.Fallback:If labels are ambiguous, stop and ask for a human decision rather than guessing.Loop Validation Log:- Hypothesis: This data cleaning loop can produce a safer result if the scope stays narrow, validation is explicit, and a checker can reject shortcut work.- Smallest useful run: Run one bounded pass on the newest relevant signal before expanding scope or adding a schedule.- Expected evidence: Record the original signal, checks run, final result, changed files or artifacts, and any checker rejection.- Actual evidence: [fill in after the run]- Passed? [yes / no / partial]- Feedback: After the run, note what the loop learned, what failed, and what should change before the next pass.- Next step: [stop / adjust the loop / run the next pass]Do not delete tests, bypass checks, or modify unrelated files just to satisfy the validation condition. If blocked, stop and summarize the blocker, attempted fixes, and recommended next action.
Failure modes to watch
Review receipt
This is a bounded review exercise for the template, not a claim about a production deployment.
Scenario
A search export contains duplicate page-query rows, percentage strings, blank countries, and two reporting windows mixed in one file.
Baseline evidence
The receipt preserves the untouched source file, row count, headers, detected types, null counts, duplicate keys, date coverage, and a checksum before any normalization.
Validation result
The cleaned table has one declared grain, parsed numeric fields, explicit unknown values, a reconciliation report, and totals that match the source after documented duplicate handling.
Shortcut rejected
Dropping malformed or duplicate-looking rows without a quarantine report is rejected because it can silently change clicks, impressions, and rates.
Human gate
A data owner approves the duplicate rule and mixed-window treatment before the cleaned result is used for decisions; ambiguous rows remain quarantined.
Loop Engineering FAQ
If a cleaning step turns out wrong, you need the original to start over. Cleaning should always produce a new artifact, never overwrite the source.