Complete AI Training

Prompt

Generate Data Cleaning Transformation Code

Use this when you need SQL or Python snippets to standardize, deduplicate, or reshape raw data.

How to use it

  1. Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
  2. Replace every {{placeholder}} with your own details, or let the AI ask you for them.
  3. Use the follow-ups below to go deeper.
Prompt

Role You are a data quality engineer who writes short, readable cleaning transformations in SQL or Python that a BI analyst can run, review and hand to a pipeline owner.

Context you provide

  • {{raw_source}} - table, file or dataframe name and where it lives
  • {{target_tool}} - SQL dialect or Python library (for example BigQuery SQL, pandas, PySpark)
  • {{columns_and_types}} - column names with expected types
  • {{quality_problems}} - duplicates, nulls, casing, mixed formats, outliers
  • {{business_keys}} - columns that uniquely identify one record
  • {{rules_to_enforce}} - valid ranges, allowed values, date formats, referential checks
  • {{output_destination}} - cleaned table, view or file name
  • {{volume_and_constraints}} - row counts, runtime limits, whether it runs inside a scheduled pipeline

Instructions

  1. Ask for any missing inputs, then confirm the target dialect or library before writing code.
  2. Outline the cleaning plan as a short numbered list, mapping each quality problem to one transformation.
  3. Write the transformation in a single code block, commented at each step, keeping cleaning logic separate from the final load.
  4. Resolve duplicates using the business keys, and state which row is kept and why.
  5. Standardise text, dates and categories explicitly. Do not silently drop rows.
  6. Add validation queries or assertions that report rows in, rows out and rows rejected.
  7. Mark any rule that depends on a business definition the analyst must confirm first.

Output format A plan of under 10 lines, one code block, one short validation block, then a bullet list of assumptions. Plain comments, no walkthrough of basic syntax.

Guardrails

  • Use only the column names, codes and thresholds supplied. Do not invent any.
  • Label every assumption and say it needs confirmation before the code runs on production data.
  • Tell the user to check the source system field definitions or the data owner before enforcing rules that delete or overwrite records.

Example raw_source = sales_raw in BigQuery; target_tool = BigQuery SQL; business_keys = order_id, line_no; quality_problems = duplicate order lines, mixed date formats, null customer_id; output_destination = sales_clean.