﻿# Invalid UTF-8 in AI corpora: quarantine bytes before replacement destroys evidence

Invalid UTF-8 in AI corpora: quarantine bytes before replacement destroys evidence. A practical data-quality guide with failure mechanisms, validation steps, acceptance evidence and primary references.

Author: Retrivium team
Updated: 2026-11-06
Canonical URL: https://retrivium.ai/journal/dq-invalid-utf8-quarantine-byte-evidence/
Language: en

A corpus importer replaces decoding errors with a replacement character and proceeds. Reviewers later cannot distinguish corrupt bytes from a replacement character that was already part of the original document.

## The mechanism that changes the example

Error replacement is a lossy transformation. A successful text export proves that output is readable, but does not prove that all source characters or byte boundaries survived ingestion.



## Define the comparison boundary

Keep decoding policy separate from later language filtering. A strict UTF-8 failure identifies a problem under that declared encoding; it does not establish that a document has no recoverable text under a source-authorized legacy encoding.

When decoding fails, retain the immutable byte-object identity and the decoder's failure location in controlled diagnostics. A repaired output must reference the original object and the repair policy. Avoid replacing every failure first and attempting provenance reconstruction afterward.

Use a genuine replacement character in a valid control document. Its presence must not automatically count as corruption. Conversely, an error-replacement decoder producing readable text must not convert the malformed source into an unexplained successful import. Acceptance should show whether the record was preserved, explicitly repaired or excluded, and which representation the model ultimately consumed.

## A constructed test case

Include a valid document containing a literal replacement character and a malformed byte object that a permissive decoder would replace. The audit must distinguish their origins without relying on the identical appearance of the decoded text.

## A reproducible validation procedure

Exercise strict decoding on known-valid, truncated and malformed inputs. Keep immutable source bytes and decoder diagnostics in a restricted quarantine. Compare downstream inclusion decisions without copying raw documents into routine logs.

Include an unchanged control and a deliberately invalid case. Verify that the checker distinguishes them before testing the complete release.

Exercise the actual preparation path, including later serialization and reload. Limit retained diagnostic content to the evidence required for this comparison.

## Evidence needed for acceptance

Evidence should identify the byte object, decoding policy, failure location and final disposition.

## Containment and recovery

A repaired document requires a new transformation identity even when its visible text looks plausible.

Quarantine an invalid release candidate or use an explicit partial-release rule. Preserve the last approved artifact and record corrections without silently rewriting historical inputs.

## Interpretation and references

Implementation references: [Python Unicode normalization](https://docs.python.org/3/library/unicodedata.html); [JSON data interchange specification](https://www.rfc-editor.org/rfc/rfc8259).

This is a proposed engineering validation, not an executed Retrivium benchmark. Documentation specifies interfaces; dataset acceptance needs its own evidence and must be repeated after relevant dependency changes.

## Related reading

Continue with [ICU normalization and text spans: preserve annotation coordinates after edits](/journal/data-guide-unicode-normalization-span-integrity/); [Documents to Markdown or JSON: preserve evidence provenance for RAG](/journal/document-markdown-json-provenance/). These guides supply adjacent context; the decision in this article remains the specific example-preservation check above.
