Replit Agent prompt to build a CSV import/export feature
CSV features look small until a real file with a broken header shows up. This prompt directs Replit Agent to build a mapping step, row-level validation with a downloadable failures file, and streamed exports scoped to the active filters. You get import and export that survive messy files from other people's systems.
Last updated
Add CSV import and export for {{resource}} records to the app in this Repl. Both directions, processed server-side, no client-side parsing of large files.
Import flow: an upload dropzone that accepts .csv only, sends the file to POST /api/import, and lands on a mapping step. The mapping step shows the first five parsed rows and lets me match CSV headers to fields, with automatic matches preselected when names align. Confirming starts the real import.
Validation: process row by row, collect failures instead of aborting, and enforce the same rules as the normal create form. On completion show imported, skipped, and failed counts, plus a downloadable failures.csv containing each original row with an added error column. Dedupe on a natural key I confirm during mapping, duplicates count as skipped.
Big files: stream the parse, never hold the whole file in memory, and run anything beyond a few hundred rows as a background job the page polls for progress. Park the uploaded file in Object Storage until the job completes.
Export: a button on the list view that exports the currently applied filters, not the whole table, streaming the response with a date-stamped filename. Escape cells that spreadsheets would treat as formulas so nothing executes on open.
Empty and error states: an empty export still returns a valid header-only file. A malformed CSV fails at the mapping step and reports the line number of the first unparseable row.
Done when: I import a file containing two bad rows, get failures.csv back holding exactly those rows, and a filtered export reopens cleanly in a spreadsheet.Customize it
Runs in your browser. Nothing you type here is sent anywhere.
Add CSV import and export for users records to the app in this Repl. Both directions, processed server-side, no client-side parsing of large files. Import flow: an upload dropzone that accepts .csv only, sends the file to POST /api/import, and lands on a mapping step. The mapping step shows the first five parsed rows and lets me match CSV headers to fields, with automatic matches preselected when names align. Confirming starts the real import. Validation: process row by row, collect failures instead of aborting, and enforce the same rules as the normal create form. On completion show imported, skipped, and failed counts, plus a downloadable failures.csv containing each original row with an added error column. Dedupe on a natural key I confirm during mapping, duplicates count as skipped. Big files: stream the parse, never hold the whole file in memory, and run anything beyond a few hundred rows as a background job the page polls for progress. Park the uploaded file in Object Storage until the job completes. Export: a button on the list view that exports the currently applied filters, not the whole table, streaming the response with a date-stamped filename. Escape cells that spreadsheets would treat as formulas so nothing executes on open. Empty and error states: an empty export still returns a valid header-only file. A malformed CSV fails at the mapping step and reports the line number of the first unparseable row. Done when: I import a file containing two bad rows, get failures.csv back holding exactly those rows, and a filtered export reopens cleanly in a spreadsheet.
Same task in other tools
Questions about this prompt
What happens to bad rows in the middle of an import?
They are collected, not fatal. The import finishes, reports imported, skipped, and failed counts, and hands back failures.csv with an error column per row, so the person fixing the data works from exact line-level reasons.
My CSVs always come from one legacy system, can I skip the mapping step?
Preseed the mapping with that system's known headers and auto-confirm when every column matches. Keep the five-row preview visible anyway, it is the earliest place a silently changed export format becomes obvious.
Large imports freeze the whole app, what did the agent get wrong?
It parsed the file in memory inside the request handler. The prompt requires a streamed parse and a background job with polling, so point it at that section and confirm the upload lands in Object Storage first.