Document parsing is the general technique of extracting text and, where possible, meaningful structure (headings, sections, tables) from a source document — the foundation every format-specific extraction approach (PDF, HTML, etc.) builds on.
Two Levels of Parsing
| Level | What It Captures | Why It Matters |
|---|---|---|
| Plain text extraction | Just the raw text content, structure discarded | Simple, works everywhere, but loses useful signal for chunking |
| Structure-aware parsing | Text plus its structural role — this is a heading, this is a table cell, this is a list item | Enables smarter, structure-aware chunking (see Chunking Strategies) and better-preserved meaning |
Example — Why Structure Matters
Plain text extraction (structure lost):
"Refund Policy Standard items may be returned within 30 days
Sale items Sale items are final sale and cannot be returned"
Structure-aware parsing (headings preserved):
{
"heading": "Refund Policy",
"sections": [
{"heading": "Standard items", "text": "May be returned within 30 days"},
{"heading": "Sale items", "text": "Final sale and cannot be returned"}
]
}
The structure-aware version makes it far easier to chunk sensibly (one chunk per section, each retaining its heading for context) rather than an undifferentiated block of run-together text.
Tables Deserve Special Handling
Naive parsing often turns a table into a confusing sequence of numbers and labels with lost row/column relationships. Where possible, preserving table structure (even as a simple markdown-style table representation within the extracted text) meaningfully improves how well an LLM can later reason about that data if retrieved.
Practical Use Case
A knowledge base with well-structured source documents (headed sections, consistent formatting) benefits significantly from structure-aware parsing feeding into structure-aware chunking — the two techniques compound, producing noticeably better retrieval quality than treating every document as an undifferentiated wall of text.
Common Mistakes
- Discarding structural information (headings, sections) during parsing, then trying to recover similar benefits later through more complex chunking heuristics
- Not specially handling tables, letting numeric data become an unreadable jumble in the extracted text
Interview Relevance
"Why would you want structure-aware parsing instead of just extracting plain text?" — it preserves signal (headings, sections, tables) that improves downstream chunking quality and helps the model reason about retrieved content more accurately.
Practice Question
Given a document with nested headings (H1 → H2 → H3), design a parsed representation that preserves this hierarchy for later chunking.