Skip to content
DataLow risk

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

Messy CSV or table cleanup
Schema normalization
Reproducible pipelines

When not to use it

Ambiguous labels needing human judgment
Data that must not be modified
Unverifiable sources

Validation checks

validation
Missing values are reported
Schema is documented
Cleaning script is reproducible
Final dataset passes validation checks

Boundaries & stop rule

!Do not silently delete rows
!Do not overwrite raw data
!Do not invent missing values without labeling imputation
Stop rule — Stop when the cleaned dataset passes validation and the script reproduces it. If labels are ambiguous, stop and ask for a human decision rather than guessing.

Copy the loop prompt

claude-goal.txt
/goal Produce a clean dataset and a reproducible cleaning script, documenting every transformation.
 
Task type: Data Cleaning
Target tool: Generic Agent
 
Work 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 reported
Schema is documented
Cleaning script is reproducible
Final dataset passes validation checks
 
Validation 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 rows
Do not overwrite raw data
Do not invent missing values without labeling imputation
 
Stop rule:
Stop when the cleaned dataset passes validation and the script reproduces it.
Maximum iterations: 4
 
Budget:
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

Silent row deletion
Overwritten raw data
Unlabeled imputation
Non-reproducible cleanup
Worked scenario review · maintained by TianMingAI · 2026-07-21

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.

Final decisionPartial

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.