The full answer
A task that fails again and again on the same input won't be fixed by retries. Find the exact file or records that cause it, decide whether the data can be skipped, repaired or must stop the pipeline, and then process the rest while quarantining the bad part, without silently losing data.
1. Identify the cause
- Read the task's error in the Spark UI (failed stage → failed task → error) or in the executor logs. Read errors such as
FAILED_READ_FILEname the file. - Check whether it's really corruption: a corrupt file, malformed rows, a schema mismatch (a column type changed), or a value that breaks a cast or a UDF. With ANSI mode on by default since Spark 4, an invalid cast fails the task instead of returning null.
- Find which records are involved: read the suspect file on its own, with
modeset toPERMISSIVEand a corrupt-record column for CSV or JSON, and use_metadata.file_pathto tie rows to files.
2. Skip or quarantine, depending on the problem
Whole files that can't be read (truncated Parquet, bad compression):
df = spark.read.option("ignoreCorruptFiles", "true").parquet("/data/events/")
Spark logs a warning and skips them. Record which files were skipped, and alert on it.
Malformed rows in CSV or JSON:
df = (spark.read
.schema("id INT, name STRING, amount DOUBLE, _corrupt_record STRING")
.option("mode", "PERMISSIVE")
.option("columnNameOfCorruptRecord", "_corrupt_record")
.csv("/data/orders/"))
Then split good and bad rows, and write the bad ones with their file path to a quarantine table.
Values that break transformations: replace cast with try_cast, and the to_date family with try_to_date / try_to_timestamp, which return null; guard UDFs against unexpected input; then count the nulls produced.
On Databricks: badRecordsPath writes bad records and unreadable files to a location with the reason, and Auto Loader's rescued-data column captures values that don't fit the schema.
3. Isolate the file if you can't skip automatically
Move the bad file to a quarantine folder, process the rest, and reprocess it after repair. If the source is a table format, restore or re-ingest the affected version (Delta's time travel and RESTORE help when a bad write caused it).
4. Fix upstream Report the issue to the producer, add validation where the data is created, and add checks at ingestion (schema enforcement, expectations) so corrupt data is stopped at the edge rather than deep in a pipeline.
5. Don't just raise retries
spark.task.maxFailures (4 by default) exists for transient problems such as a lost executor or a network error. Raising it, or turning on speculation, only repeats the same failure on bad data.
6. Decide the policy
Agree with the data's owners when skipping is acceptable: for some data (finance, compliance) a single bad record should stop the pipeline, which is what FAILFAST is for; for others (clickstream), quarantining a small fraction is fine as long as it's measured.
Last updated 16 October 2026
Sources