TECHNOLOGY

JSONL and str.splitlines: preserve Unicode paragraph characters inside records

In this article
THE QUICK TAKE

Keep delimiter policy, decoded text preservation and the parsed record identity comparison.

A corpus loader decodes an entire JSONL file and calls str.splitlines. A valid Unicode paragraph separator inside a JSON string is treated as another line boundary, splitting one training record into invalid fragments.

The mechanism that changes the example

Python text line boundaries are broader than the physical record delimiter declared by JSONL. A Unicode separator permitted inside JSON string data must not become a record boundary merely because a convenience text method recognizes it.

Define the comparison boundary

Use a physical-record iterator whose delimiter contract matches the file format. Python str.splitlines recognizes additional Unicode line boundaries, including characters that can legitimately occur inside a JSON string.

The fixture must contain the actual separator character in UTF-8, not merely the ASCII spelling of a backslash-u escape. An escaped spelling does not exercise the same broad text-splitting path. Keep an ordinary escaped newline as a separate valid control and an unescaped ASCII newline inside a string as an invalid control.

Parse each physical record with a JSON parser and compare decoded values and stable record identities. If malformed rows are quarantined, retain their physical source location without automatically publishing text contents. Counting parser errors alone is insufficient: a permissive recovery stage can discard the split fragments and silently shorten the corpus.

A constructed test case

Place an actual Unicode paragraph separator inside a quoted JSONL string while retaining ordinary record newlines between values. Compare parsed record identity under delimiter-aware reading and broad splitlines, without replacing the in-string character before the comparison.

A reproducible validation procedure

Construct a UTF-8 JSONL fixture containing an actual U+2028 inside a quoted text value and ordinary record newlines outside it. Compare broad text splitting with delimiter-aware record iteration, then parse and reconcile exact record identities and text content.

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

Keep delimiter policy, decoded text preservation and the parsed record identity comparison.

Containment and recovery

An unescaped ASCII newline inside a JSON string remains invalid; this fixture concerns a different Unicode character.

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 line splitting; JSON data interchange specification.

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.

Continue with JSON Lines for AI data: a record boundary is not a feature schema; Documents to Markdown or JSON: preserve evidence provenance for RAG. These guides supply adjacent context; the decision in this article remains the specific example-preservation check above.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles