How to Fix CSV Import Errors: Column Shifts, Broken Quotes & Mismatches
Quick Answer
CSV import errors are caused by structural syntax violations such as unescaped quotes, mismatched column delimiters, embedded newlines, and ragged row lengths. Repairing them requires enforcing RFC 4180 compliance, standardizing separators, padding or trimming uneven columns, and validating schemas before database ingestion.
Key Facts:
- Ragged rows occur when records have more or fewer delimiters than the schema header row.
- Unescaped quotes trigger runaway multiline parsing that swallows thousands of valid rows.
- Database bulk loaders fail immediately upon encountering mismatched field counts or type mismatches.
- CSVFixKit identifies ragged rows, standardizes delimiters, and stages repairs in your browser.
1. Understanding Why CSV Imports Crash Databases and CRMs
CSV (Comma-Separated Values) remains the universal lingua franca of data exchange. Yet despite its apparent simplicity, the CSV specification (formally documented in RFC 4180) is notoriously fragile. A single unescaped quotation mark, an inconsistent line ending, or an unquoted newline inside a customer comment can cause database bulk-insert routines (such as PostgreSQL \copy or MySQL LOAD DATA INFILE) to reject an entire batch of hundreds of thousands of records.
Unlike modern structured serialization formats like JSON, Avro, or Parquet, CSV files carry no schema metadata. There are no built-in field types, no explicit table definitions, and no length constraints. When import pipelines parse raw text, any structural flaw immediately causes catastrophic cascading failures:
- Column Shift Errors: A row with one missing or extra delimiter causes every subsequent cell in that row to shift into the wrong database column. Email addresses get written into phone number fields, while numeric IDs end up in date columns, triggering strict database type casting errors.
- Runaway Multiline Parsing: If a text cell opens a double quote (
") but fails to close it before the line break, compliant RFC 4180 parsers consume all subsequent rows as part of that single cell until they encounter another quote. This can swallow thousands of legitimate rows into a single giant corrupted field. - Silent Truncation: In legacy systems or permissive spreadsheet software, rows with mismatched column counts are often truncated without throwing errors, permanently destroying data without administrative notification.
2. The Top 5 CSV Import Errors Diagnosed
A. Unescaped Quotation Marks inside Text Fields
According to RFC 4180, if a field contains a literal quotation mark, the field must be enclosed in double quotes, and the internal quote must be escaped by prefixing it with a second double quote (""). For example:
Broken: 101,"Heavy-duty 12" monitor stand",49.99
When an unescaped quote appears mid-cell, standard parsers assume the string has ended. The subsequent space or character violates CSV syntax, throwing errors like "Quote character not followed by delimiter" or "Found unescaped quote on line 42".
B. Embedded Newlines in Multiline Comments
Customer support feedback, shipping instructions, and product descriptions frequently span multiple lines. RFC 4180 permits newlines within fields only if the field is fully enclosed in double quotes. If an export script forgets to wrap multiline fields in quotes, each line break creates an orphan fragment with too few columns, instantly breaking downstream parsers.
C. Ragged Rows (Inconsistent Column Counts)
If your header contains 15 columns, every single row in the document must contain exactly 14 delimiters separating 15 cells. In real-world data feeds, trailing empty cells are frequently omitted by sloppy export generators, producing rows with only 12 or 13 columns. Conversely, raw text containing unquoted commas creates rows with 16 or 17 columns.
D. Delimiter Conflicts (Commas, Semicolons, and Tabs)
In regions that use commas as decimal separators (e.g. France, Germany, Brazil), spreadsheet software defaults to exporting CSV files using semicolons (;) rather than commas. If your CRM expects commas, it treats the entire semicolon-separated line as a single massive column, failing validation immediately.
E. Mixed Line Endings (CRLF, LF, and Lone CR)
Files compiled across diverse platforms often contain mixed line endings: Windows (\r\n), Unix/Linux (\n), and legacy macOS (\r). When a single CSV file contains inconsistent line terminators, streaming chunk processors can split records inappropriately, creating orphan rows.
3. Step-by-Step Fixes in Excel, Google Sheets, and LibreOffice
In Microsoft Excel:
- Never double-click the file to open it directly; instead, open Excel and go to Data → From Text/CSV.
- In the preview screen, inspect the detected Delimiter (Comma, Semicolon, Tab, Space, or Custom). If columns are merged together, change the delimiter dropdown to match your data.
- Click Transform Data to launch the Power Query Editor.
- Power Query automatically flags error rows in red. Use Remove Rows → Remove Errors or apply Replace Errors to substitute safe fallback values.
- Click Close & Load to import clean, normalized rows.
In Google Sheets:
- Create a blank spreadsheet and choose File → Import → Upload.
- Under Separator type, do not rely solely on "Detect automatically" if your file contains non-standard delimiters; choose Custom and explicitly enter your delimiter character.
- Uncheck "Convert text to numbers, dates, and formulas" if you wish to prevent numeric IDs from being altered.
- Click Import data. If column shifting has occurred, use Data → Split text to columns to correct misaligned fields.
In LibreOffice Calc:
- Launch LibreOffice and choose File → Open to trigger the Text Import dialog.
- Under Separator Options, check Separated by and select exactly one delimiter (Comma, Semicolon, or Tab).
- Under Text delimiter, ensure
"is specified. Check Quoted field as text to prevent numeric coercion. - Check the preview grid at the bottom to ensure columns align perfectly with their headers before clicking OK.
4. Automated Diagnostics and Safe Repairs in CSVFixKit
Resolving large files manually is tedious and error-prone. CSVFixKit provides automated streaming diagnostics directly in your web browser:
- Automatic Delimiter Detection: Scores potential delimiters (
,,;,\t,|) across sample lines to identify consistent column counts. - Ragged Row Alignment: Trims harmless trailing empty cells or pads deficient rows with empty string placeholders to restore structural uniformity.
- Quote Sanitization: Normalizes unbalanced quotes and unescaped delimiters while maintaining full RFC 4180 compliance.
- 100% Client-Side Privacy: Your sensitive CSV data never leaves your computer; all parsing occurs in high-performance local Web Workers.
5. Common Mistakes When Troubleshooting CSV Errors
- Blindly Deleting Short or Long Rows: Truncated rows often contain vital customer data that was simply pushed into a newline. Deleting ragged rows without inspecting them first can purge crucial transactions. When resolving duplicate entries, see our guide on how to remove duplicate rows from CSV safely rather than deleting rows blindly.
- Editing Large CSVs in Basic Text Editors: Standard text editors often wrap long lines automatically or alter line endings upon saving, corrupting byte alignments in huge files.
- Ignoring Header Byte Order Marks: Leaving a UTF-8 BOM in a CSV fed into an automated SQL ingestion script causes the database to read the first column header as
id. Learn more in our comparison of UTF-8 vs UTF-8 with BOM in CSV files.
Frequently Asked Questions
What does "expected 12 fields, saw 13" mean during a CSV import?
This indicates that on that specific line, the parser found more delimiters than exist in your header row. It typically happens when a text field (such as an address or company name) contains an unquoted comma.
How can I import a CSV containing multiple delimiters?
A valid CSV file must use a single consistent delimiter throughout the document. If your file mixes commas and semicolons, you must first normalize the file using CSVFixKit or a text processing script before importing into databases.
Why do database bulk loaders report "string data right truncation" on CSV files?
This occurs when an unescaped double quote collapses two adjacent rows into a single oversized cell. The parser treats the merged multi-line text as a single string, exceeding the target database column width (e.g. VARCHAR(255)). Inspecting ragged lines in CSVFixKit isolates the exact row containing the runaway quote.
How does CSVFixKit repair ragged rows without corrupting relational IDs?
CSVFixKit inspects the header length: if a trailing column was omitted because it was empty, it appends empty string fields to reach the required column count. If extraneous trailing empty fields exist, it trims them to match the schema header. Fields containing data are never deleted without explicit manual confirmation.
Authoritative Standards & Verified Sources
CSVFixKit relies on standardized file specifications, encoding algorithms, and Unicode Consortium documentation:
- IETF RFC 4180: Common Format and MIME Type for Comma-Separated Values (CSV) Files
- IETF RFC 3629: UTF-8, a transformation format of ISO 10646
- MDN Web Docs: WHATWG TextDecoder Web API Reference
7. Related Guides
Why CSV Shows é (Mojibake)
Fix encoding mismatches and corrupted accented characters.
UTF-8 vs UTF-8 BOM
Learn when to include or strip the Byte Order Mark in CSV files.
Remove Duplicate Rows Safely
Safely deduplicate records without losing valid transactions.