Engineering / Engineering journal

CSV Imports for SaaS: Validation and Recovery

Customers arrive with their own column names, encodings and duplicates. A good importer makes those differences visible before writing anything and keeps failures recoverable.

Sylantix Engineering Team7 min read
A spreadsheet import preview on a laptop beside printed data sheets.
Sylantix / Engineering journalCSV · Data Import · SaaS
In this article 10 sections
TL;DR

Key takeaways

  • Detect encoding and delimiter, show a preview, and let users map columns to fields.
  • Run a dry run with per-row errors, and state whether the import is all-or-nothing or partial.
  • Use a stable match key so re-importing a corrected file updates records instead of duplicating them.
  • Run large files as background jobs with limits, progress and a downloadable error file, and neutralize formulas in exports.

The customer has a file, not your data model

A new customer wants to import their contacts. Their file has "Account", "Contact name" and "Owner"; your product expects organization, person and assigned user. Some rows refer to organizations that already exist. Dates use a format nobody has confirmed.

A useful import helps the customer resolve these differences before anything is written. The upload button is only the entrance. For a SaaS product, a clear import also shortens onboarding, because the customer starts with familiar records instead of an empty workspace.

This article follows the importer's stages: reading the file, mapping, matching, dry run, committing, running at scale and handling output safely.

Read the file without guessing silently

Parse with a CSV parser, never a split on commas. Quoted values can contain commas and line breaks; RFC 4180 describes the common conventions, and real files deviate from it.

Two things vary most:

  • Encoding. Excel's plain "CSV" save on many systems uses a legacy code page such as Windows-1252, while "CSV UTF-8" adds a byte order mark. Try UTF-8 first, strip a BOM if present, fall back to a detected legacy encoding and show the preview so the user can see whether accented names look right.
  • Delimiter. In locales where the comma is the decimal separator, spreadsheet tools often export with semicolons. Detect among comma, semicolon and tab by checking which gives a consistent column count over the first rows, and let the user override it.

Also handle blank trailing lines, duplicate header names and rows with the wrong number of fields by reporting them, not dropping them.

Let people map columns

Show the first few rows and a mapping step: each product field on one side, a dropdown of file columns on the other. Pre-select likely matches by comparing normalized names ("E-mail" and "email"), but let the user change every one. Highlight required fields that are unmapped, keep the original column names visible and offer to save the mapping for the next import from the same source.

Treat identifiers and dates carefully. A customer number of 00127 is not 127, and spreadsheets silently strip leading zeros, so import such columns as text. A value like 03/04/2026 needs a confirmed convention. Ask the user to choose the date format, and show a few parsed examples. Guessing correctly on nine rows is worse than rejecting the tenth, because the wrong one may go unnoticed.

Decide create, update and blank-cell behavior

For each row the importer must know whether it creates a record, updates one or is a duplicate. Choose a match key per entity, ideally the customer's own external ID, and state it in the interface: "Match organizations by External ID. Create a new organization when the ID is not found." Say what happens when two rows share a key (usually: reject the later one with an error).

Email addresses are tempting as keys but can be shared or changed. Blank cells need a rule as well. Does a blank phone number leave the existing value alone or clear it? Offer a clear default, such as "leave unchanged", with an explicit option to clear, and preview the effect.

Dry run before committing

Run validation as a dry run first. It should report how many records would be created, updated, skipped and rejected, without writing anything. Separate parse errors (a malformed row) from business errors (an owner who is not a member of the workspace).

For each rejected row give the row number, the column and a fix the user can apply: "Owner is not a member of this workspace" beats "invalid value". Show the first 20 or so on screen and offer the full list as a download. Enforce rules on the server regardless of any browser checks, including tenant boundaries, and tell the user that the final run rechecks constraints if data changed since the preview.

Partial accept or all-or-nothing

Both are legitimate. Tell the user which one they are getting.

  • All-or-nothing: one transaction, suitable for small files and for data with strong cross-row dependencies. A single bad row blocks everything, which is easy to reason about.
  • Partial accept: valid rows are applied and invalid ones reported. Suitable for large files, but it must be safe to run again.

Suppose 9,800 rows succeed and 200 fail. The customer should download the 200 rejected rows with an error column, fix them and upload that file, without duplicating the 9,800. That requires idempotent re-imports.

Make re-imports idempotent

Idempotency comes from stable keys. If every row carries an external ID that matches an existing record, importing it again updates the record to the same values, which changes nothing. When files have no natural key, offer to generate one from a combination of fields (for example email plus company), and warn that this match is only as good as the fields.

Track the import job and per-row outcomes (created, updated, unchanged, rejected with reason). Storing a row hash lets a re-import skip unchanged rows quickly. Reuse the same approach as in webhook retries and idempotency: the key, not the attempt, defines what happened.

Run big files in the background

Do not process a large file inside the upload request. Accept the upload, store it, create an import job and process it in a worker in batches, for example 500 rows at a time. Give the job a status page that survives closing the tab, with counts for processed, succeeded and rejected rows, and an email or in-app notification on completion.

Set limits and publish them: maximum file size, row count and columns per plan or per import. Stream the file instead of loading it into memory, and make the worker resumable so a restart continues from the last committed batch. Throttle per tenant so one large import does not starve everyone else. Large imports also generate activity worth recording in an audit log, such as who imported what, and how many records changed.

Treat files in and out as untrusted

Spreadsheet applications may interpret a cell beginning with =, +, - or @ (and sometimes a tab or carriage return) as a formula. When your product exports data or error files that contain user-supplied text, a malicious value can become a formula that runs when opened. OWASP describes this in its CSV injection guidance.

A common mitigation is to prefix such cells with a single quote so they display as text, applied only to text columns and not to numbers you want to remain numeric. Quoting a field solves parsing, not formulas, so test your approach in the spreadsheet applications your customers use. Treat the uploaded file itself as untrusted too: check size, content type and encoding, and never render cell content as HTML.

Keep uploads and error files access-controlled and delete them after a defined period. An error file containing the whole customer list deserves the care of the original upload.

Downloadable error file and a checklist

The best error output is a copy of the user's own file with one extra column explaining each problem, so they can fix and re-upload it. Keep the original row order and number, and include a short summary at the top of the page rather than in the file.

  • Encoding and delimiter detected and overridable.
  • Mapping step with saved mappings.
  • Explicit match key and blank-cell rule.
  • Dry run with per-row errors.
  • Stated all-or-nothing or partial behavior.
  • Idempotent re-import, background job, progress, limits.
  • Formula-safe exports and error files.

Before release, test duplicate rows, leading-zero IDs, mixed dates, a semicolon-delimited file, a Windows-1252 file with accents, missing relationships and an interrupted retry. Ask someone unfamiliar with the product to fix the errors using only the messages shown. Our SaaS development work includes these onboarding workflows. If the file is one part of a larger operational workaround, internal tools versus no-code helps assess whether the surrounding process needs attention too.

Facing this in your own product?

Describe your situation in a few sentences. Our engineering team replies within 24-48 hours on business days, and the first 30-minute consultation is free.

Sylantix Engineering Team

Written by the senior engineers who build these systems for clients: backends, AI features, mobile apps and the infrastructure under them. Questions about your own case go straight to them.

About the team →