published fresh until

DuckDB stops on a bad CSV line: how do I skip and list bad rows?

Summary If DuckDB stops on a malformed CSV row, ignore_errors = true skips bad rows; store_rejects = true also records line, column, error type, and original line (truncated to 10,000 characters by default) for review.

Not for pandas running out of memory; see pandas-memoryerror-big-csv-fewer-columns-dtypes-parquet-chunks

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

The symptom

You (or your agent) ran DuckDB on a CSV, and it stops with an error naming a line, for example a value that cannot be cast to INTEGER, too many or too few columns, or an unquoted value. The file has a few bad rows, and you want to load the good ones and see the bad ones.

What DuckDB's docs say

From the DuckDB page on reading faulty CSV files (current docs):

  • By default DuckDB stops at the first structural error. The error types it detects are CAST, MISSING COLUMNS, TOO MANY COLUMNS, UNQUOTED VALUE, LINE SIZE OVER MAXIMUM and INVALID ENCODING. The message includes the line number, the original line, the column, and suggested fixes.
  • ignore_errors = true skips any row that would cause a structural error. With projection pushdown, if your query selects only some columns, rows are not rejected for a bad value in a column you did not select.
  • store_rejects = true skips faulty rows and records them in two temporary tables, reject_scans and reject_errors. reject_errors has one entry per error with scan and file ids, line, byte position, column index and name, error type, the original CSV line (truncated to 10,000 characters by default) and an error message. Set rejects_line_size_limit = 0 to retain the full line. A line with several errors gives several entries.
  • rejects_scan and rejects_table rename those tables, and rejects_limit caps how many are stored (0 means no cap).
  • If a type error comes from auto-detection guessing a wrong type from the sample, the error message suggests a larger sample_size, for example sample_size = -1 to scan all values, or setting the column type yourself, such as VARCHAR for a date column.

A working pattern

Load with the rejects table on, check how many rows were dropped, then look at them:

FROM read_csv('export.csv', store_rejects = true);
FROM reject_errors;

Ask the agent to report the count of good rows, the count of rejected lines grouped by error type, and a handful of examples before it continues. If one column is the culprit, read it as VARCHAR and convert later with a cleaning step you can inspect.

Common mistakes

  • Using ignore_errors and never looking at what was dropped. Totals then silently disagree with the source.
  • Raising sample_size when the real problem is a stray text value; the rejects table tells you which.
  • Forgetting the reject tables are temporary and vanish with the session. Export them if you need them later.

Caveats

I have not run these commands myself; the options are as documented in the page above. The page does not describe strict_mode, null_padding or all_varchar as settings, so check the main CSV import docs for those.

Sources

Primary source, re-read on 15 November 2026: the DuckDB page Reading faulty CSV files.

  • Confirms: ignore_errors (default false), store_rejects (default false), rejects_table (default reject_errors), rejects_scan (default reject_scans), rejects_limit (default 0, no limit), sample_size default 20480 with a suggestion to try -1, and the reject_errors columns (scan and file ids, line, byte position, column index and name, error type, the CSV line (truncated to 10,000 characters by default) and the error message).
  • Rechecked on 15 November 2026: the list of error types and the projection-pushdown note. The page mentions null_padding and all_varchar only in an example and says nothing about strict_mode, which matches the caveat above.

Started from a post by @DuckDB documentation, packaged by the editor. Original post

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# DuckDB stops on a bad CSV line: how do I skip and list bad rows?
Summary: If DuckDB stops on a malformed CSV row, `ignore_errors = true` skips bad rows; `store_rejects = true` also records line, column, error type, and original line (truncated to 10,000 characters by default) for review.
Copy for agent
get the whatworks thread duckdb-read-csv-stops-on-bad-line-skip-and-list-rejected-rows and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread duckdb-read-csv-stops-on-bad-line-skip-and-list-rejected-rows
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks