wowprompt

CSV bulk import with row-level validation and an error report

Builds a CSV import feature that checks every row before saving, imports the good rows safely, and gives the user a downloadable file of the rejected rows with the reason for each. Use it for product, customer, price or stock uploads where one bad row should not break the whole file.

Import code with a validation pass and batched inserts, a table of rules per column, a sample error report file, and tests for malformed and duplicate rows
The output this prompt produced, unedited.

The prompt

Role

You are a backend developer who has supported bulk uploads from non-technical users. You assume every file will contain something unexpected.

Task

Write a CSV import for the entity below that validates, imports and reports back.

Inputs

  • Language, framework and database: [e.g. Python with Django and PostgreSQL]
  • Entity and columns: [e.g. products: sku, name, price, stock, category]
  • Rules per column: [e.g. sku required and unique, price a positive number with two decimals, category must exist]
  • Existing rows: [create only, or update when the key already exists]
  • Expected file size: [e.g. up to 50,000 rows]
  • Who uploads: [e.g. store staff using a spreadsheet saved as CSV]

Steps to follow

  1. Check the file first: size limit, CSV type, encoding (handle UTF-8 with a byte order mark), the expected header row.
  2. Parse row by row in a stream, not by loading the whole file into memory.
  3. Validate each row against the rules, collect every error per row rather than stopping at the first.
  4. Catch duplicates inside the file as well as against the database.
  5. Insert or update valid rows in batches inside transactions; report how many succeeded.
  6. Write rejected rows to an error file with the original columns plus row number and reason.
  7. For large files, run the import as a background job and show progress.

Output format

  1. | Column | Rule | Error message shown to the user |
  2. The import code with comments.
  3. A sample error report with three rejected rows.
  4. Tests: a clean file, a wrong header, bad values, duplicate keys, an empty file, a file with a byte order mark.

Guardrails

  • Never build SQL from cell values; use parameterised queries or the ORM.
  • Guard against spreadsheet formula injection in the error file: prefix cells that begin with =, +, - or @.
  • Error messages say what to fix in plain words, never a stack trace.
csv importbulk uploaddata validationfile uploadbatch processingerror report

How to run this

Copy the prompt and paste it into Gemini, then set the aspect ratio to 3:4. No reference photo is needed for this one.

The prompt is written in Markdown with each part under its own heading, which is what the copy action hands over. Change one section at a time, keeping the rest intact, so you can tell which change did the work.

Related prompts

All productivity