OpenAI Batch Error File Reconciliation Without Lost Rows
OpenAI Batch error file reconciliation requires a two-artifact accounting pass across successful output lines, failed error lines, the local submission manifest, and Batch request counts. This guide defines occurrence checks, row states, partial-result handling, expiry controls, and downstream write rules that expose missing or duplicate work.

OpenAI writes successful Batch requests to the output file. Failed requests go to the file referenced by error_file_id. Those artifacts form one accounting set, and a reconciler that downloads only output_file_id can mark a batch complete while silently abandoning every failed source row.
I want one terminal explanation for every submitted custom_id. That includes the awkward rows that appear twice, appear in neither file, or arrive after a cancellation.
TL;DR
- Download and verify both output and error artifacts before closing row-level reconciliation.
- Count each custom_id before joining results. Duplicate lines must not overwrite one another.
- Compare accepted rows with the immutable submission manifest and the Batch request counts.
- Separate provider completion from schema acceptance, downstream authorization, and final write state.
Two result files form one ledger
OpenAI's Batch API guide says the output JSONL contains one response line for every successful input request, while failed requests place their error information in the artifact identified by error_file_id. The guide also warns that output order may differ from input order. It directs clients to join with custom_id.
Start reconciliation only after retrieving the current Batch object. Record its status, output_file_id, error_file_id, request counts, and relevant timestamps, then download every available result artifact through the Files API. Hash the raw bytes on receipt, before parsing a line.
Keep the file roles explicit. An output line is a provider success record. An error line is a provider failure record. Neither role proves that the application accepted the body or committed its downstream action.
The signed audit records guide covers integrity for routed request decisions. Batch artifact hashes extend that custody trail to asynchronous result files.
Count identifiers before building the join
A dictionary keyed by custom_id is a tempting first parser, but it also implements "last line wins" behavior and hides duplicates. Parse each JSONL line into an occurrence record first. Preserve source file ID, byte or line position, raw-line digest, parsed identifier, response status, and error code when present.
Next, calculate occurrence counts across both files. Accept a normal row only when its identifier appears exactly once and belongs to the expected manifest namespace.
Quarantine an unknown identifier. Hold any identifier found in both artifacts, even if one line looks successful. A duplicate inside one file gets the same hold.
Malformed lines need their own artifact-level exception because they may lack a usable custom_id. Preserve the raw-line digest and position. Never discard the line, then claim that the file's parsed count matches its physical record count.
The AI data lineage guide provides the wider source-to-output chain. This occurrence stage protects the narrower join between submitted rows and provider results.
Manifest subtraction exposes missing work
Load the immutable set of submitted custom_id values. Subtract accepted output and error identifiers. Anything left is missing from the downloaded artifacts and must remain in investigation state until the Batch status, request counts, and artifact retrieval are consistent.
OpenAI's Batches reference exposes request counts for completed, failed, and total requests, along with status and file identifiers. Use those values as an independent cross-check, but remember that they are batch-level provider fields and cannot replace your row inventory. A count of 9,999 completed requests says nothing about which one of 10,000 source records is absent.
Reconciliation should produce named totals for expected rows, accepted successes, accepted errors, duplicates, unknowns, malformed physical lines, and missing identifiers. The arithmetic must balance before downstream closure.
A green dashboard tile saying "batch completed" is too coarse. I would block the job on one unexplained row, even when the other 49,999 responses are ready.
Cancellation and expiry need explicit branches
The Batches reference states that cancellation can take up to 10 minutes. A cancelled batch can have partial results available in the output file.
Treat cancellation as a batch state, then reconcile every artifact that exists. Rows absent from both files receive a cancellation-specific unresolved state rather than a generic failure invented by the client.
Expiry creates a different branch. OpenAI documents batch_expired error lines for requests that miss the completion window. Those are normal error-artifact records, so map them to their manifest rows through custom_id and preserve the provider code and message as received.
Result-file retention has its own clock. The guide says output and error files expire 30 days after file creation by default, while Batch creation can set output_expires_after between one hour and 30 days. Schedule retrieval well before that boundary. Record the configured policy, and alert on any batch whose artifacts remain unverified near the deadline.
A missed download is an application control failure. Calling those rows provider failures would falsify the record.
Provider success precedes application acceptance
A successful output line still has work ahead. Validate the line shape, expected endpoint response schema, source-row ownership, and target authorization before executing the downstream write under an idempotency rule tied to custom_id and the intended destination.
Use separate row states such as provider_succeeded, provider_failed, quarantined, validated, write_pending, and written. Consider a worker that commits the database update and crashes before acknowledging it. The next attempt should discover the prior commit rather than apply the model result twice.
Preserve the provider request identifier found in a successful result under its own field. The batch ID belongs in the job record. Store input, output, and error artifact IDs in separately named fields because each supports a different investigation.
The AI audit log schema gives the identity and policy fields around a request. The reconciliation row adds provider disposition and downstream commit evidence.
A destructive fixture should break the accounting
Build a fixture from ten expected manifest rows. Put six shuffled successes in the output artifact and two failures in the error artifact. Duplicate one success, insert one unknown error identifier, omit two expected rows, and truncate the final physical line.
The reconciler should report the duplicates and unknown record without overwriting evidence. It should also identify both missing manifest rows, preserve the malformed line digest, and refuse to mark the set balanced. Then add a corrected artifact pair. Verify that each expected identifier receives one provider disposition.
Run the same files through two workers at once. Only one downstream commit should win for each accepted success.
Now repeat the test with a crash after the target transaction commits but before the reconciliation row changes to written.
Print the final row-state totals on a plain terminal screen during release review. If the columns fail to sum to ten expected rows plus quarantined extras, the test failed. That visual check catches accounting mistakes hidden by a friendly progress bar.
DeepInspect
DeepInspect can enforce policy on authenticated user or agent HTTP calls deliberately routed through its proxy, including approved Batch submission traffic. It can record identity, route, classification, policy version, and the allow or deny decision for those exchanges.
The application owns result-file retrieval, artifact hashing, custom_id occurrence counting, manifest subtraction, row-state transitions, and downstream commits. DeepInspect does not download OpenAI files. It does not decide that a batch has reconciled. Provider calls and file retrievals that bypass the routed path remain outside its visibility.
Join the routed submission decision to the application's batch record. Keep result handling in the reconciliation system designed for it.
Book a demo today.
Frequently asked questions
- Is error_file_id always present?
The Batch object defines
error_file_idas optional. Fetch the current object. Process the artifact when the field is populated.An absent field cannot be treated as proof that every row succeeded. Compare available artifacts, the provider request counts, Batch status, and your expected manifest before closing reconciliation.
- Can request counts replace a custom_id manifest?
Request counts provide a valuable independent total. They cannot identify the specific source row behind a success or failure.
Keep the immutable manifest and join each result by
custom_id. Use counts to detect disagreement between the row-level join and the provider's batch-level view.- What should happen to batch_expired rows?
OpenAI documents
batch_expiredas an error record with the originalcustom_id. Preserve that provider disposition. A separate application policy should decide if the work enters a new batch.A retry becomes a new submission event with its own batch and artifact identifiers.
- When is reconciliation complete?
Completion requires every expected manifest row to have one explainable provider disposition, every physical result line to be accepted or quarantined, and every successful result to have a recorded application outcome. The totals must balance against the provider request counts or carry a named investigation exception.