🗂 File Operations · 5 min read
Check a CSV Export After an Outage: 5 Tests Before You Trust the File
An interrupted export almost never announces itself. The download completes, the file opens, the header looks right — and the last several thousand rows are simply not there. That is the dangerous shape of failure: everything looks normal, so nobody checks until a number in a report is wrong. The five tests below take about two minutes and cost nothing.
Why outages produce quiet failures
When a browser download or an application export is cut short, three different things can happen. The connection can drop mid-stream and leave a file that is simply shorter than the source. The write can be interrupted between two rows, leaving a final line that stops in the middle of a value. Or the data can survive intact while the encoding changes, because the re-save used the operating system default rather than the original charset.
None of those raise an error at the point of use. A CSV has no checksum, no schema and no footer telling you how many rows it should contain. Whatever completeness you need, you have to assert yourself.
Test 1 — Row count against the source
Get the count from where the data came from: the export dialog, the database, the report the file was generated from. Then count the file. If the two differ, stop here; nothing else matters until the export is complete.
Counts are easy to be off by one because of the header row. Decide once whether you are counting data rows or all rows, and use the same convention on both sides.
Test 2 — The last line
Open the file in a plain text editor and look at the end. A complete CSV ends with a line break. A truncated one often stops mid-value, sometimes mid-quote, which is why a parser may report an unterminated string at the very end.
This single check catches the majority of interrupted downloads, and it needs nothing but a text editor.
Test 3 — Encoding
Question marks, black diamonds, or accented letters turning into symbols mean the bytes were interpreted with the wrong charset. The common pair is UTF-8 versus a legacy Windows code page.
The reliable move is to decode explicitly rather than let the application guess: try UTF-8 first, then a single-byte fallback. If the file was already damaged by a lossy re-save, the original characters are gone and only a re-export recovers them. Background and fixes: garbled CSV in Excel.
Test 4 — Delimiter consistency
A file can use commas, semicolons or tabs; what it cannot do is change halfway. When it does, rows suddenly have a different number of fields, and any downstream import either fails or shifts every column by one.
In practice this appears after an export is produced under a different locale: a decimal comma forces the writer to switch the delimiter to a semicolon. If half the file came from one system and half from another, the file will look fine to the eye and be wrong to a parser.
Test 5 — Empty and shifted columns
Count empty fields per column. A column that was populated before the incident and is empty after it is a data problem, not a formatting one — and it is invisible in a spreadsheet until you sort by it.
Running the file through the CSV analyzer surfaces rows, columns, empty-field counts and type guesses in one pass, which covers tests 1, 4 and 5 at once without writing anything.
The same five checks as a script
If the file is too large for a spreadsheet, or you want the check to be repeatable, this reads the bytes and reports the three deterministic signals. Nothing is uploaded anywhere.
import csv, io, sys
from pathlib import Path
p = Path(sys.argv[1])
raw = p.read_bytes()
# 1. does it end with a line break? (a cut-off write usually does not)
print("ends_with_newline:", raw.endswith(b"\n") or raw.endswith(b"\r\n"))
# 2. which encoding survives a strict decode?
for enc in ("utf-8-sig", "utf-8", "cp1252", "latin-1"):
try:
text = raw.decode(enc)
print("decodes_as:", enc)
break
except UnicodeDecodeError:
continue
# 3. rows, and how many fields each one has
rows = list(csv.reader(io.StringIO(text)))
widths = [len(r) for r in rows]
print("rows_including_header:", len(rows))
print("field_counts:", sorted(set(widths)))
print("ragged_rows:", sum(1 for w in widths if w != widths[0]))Read the output in order: if ends_with_newline is False, treat the file as truncated and re-export. If ragged_rows is greater than zero, look at the delimiter before blaming the data. If it decodes as cp1252 rather than UTF-8, expect character problems in any system that assumes UTF-8.
What to do with a failed check
| Symptom | Cause | Fix |
|---|---|---|
| Fewer rows than source | Write interrupted | Re-export; the missing bytes were never written |
| Last row incomplete | Cut mid-value | Drop the partial row, then re-export the tail only |
| Symbols instead of letters | Wrong charset | Re-export as UTF-8; convert if the bytes survived |
| Rows shift by one column | Delimiter changed mid-file | Normalise to one delimiter before importing |
One habit makes all of this cheap: keep the export dialogue’s row count in the filename or in a note next to the file. When a number is already written down, verifying the file takes seconds and the decision is not a judgement call.
Frequently Asked Questions
How can I tell if a CSV export was cut off?
Compare the row count with the source, then open the end of the file. A truncated export usually has no trailing line break, or its final row stops mid-value. Both are visible in any text editor in a few seconds.
Why did my CSV open with question marks or odd characters after a re-save?
The file was re-encoded, usually from UTF-8 to a legacy single-byte code page (or the reverse). The bytes are fine; the interpretation changed. Re-export as UTF-8, or open with an explicit encoding instead of letting the application guess.
Is a CSV with the wrong number of columns corrupted?
Not necessarily corrupted, but not reliably parseable. It usually means the delimiter changed mid-file, or an unquoted value contained the delimiter. Both show up as rows with a different field count, which is easy to count programmatically.
Do I need to re-export, or can I repair the file?
If rows are missing from the end, only a re-export recovers them — the bytes were never written. If the file is complete but mis-encoded or mis-delimited, it can be repaired by converting, which is cheaper than re-running the export.
Run the Checks Without Writing Code
Upload the export and see row count, column count, empty fields and type guesses — before anyone reads a number from it.
Related reading
File Operations — other guides that pair well with this one.
- Pandas read_csv and Too Many Columns: Missing or Failing
- Why Is My CSV a Text File? Because It Is
- Compare Two CSV Files Online
- Free CSV Viewer Online
Browse all guides in the NoCodeCSV blog.