Back to Resources
Document Processing RAG MAY 2026 · 12 min read

From Documents to Insight: How to Extract Structured Data from Word, PDF, and Spreadsheet Files

A five-stage pipeline for turning the raw document formats that populate enterprise contract repositories — scanned PDFs, .docx with tracked changes, spreadsheet-embedded terms — into reliable, queryable structured data.

Enterprise contract repositories are not homogeneous. They are collections of documents that arrived over years or decades, from dozens of counterparties, through multiple systems, in whatever format the generating system produced. A legal archive built up over ten years might contain digitally-native PDFs from the last two years, scanned images from older paper agreements, Word documents in various versions with and without tracked changes, email attachments, and terms embedded in spreadsheets or forms.

This heterogeneity is the central challenge of contract extraction at enterprise scale. A pipeline that performs well on one format performs poorly on another. The five-stage architecture described here is designed to handle all of them — not by finding a common approach to all formats, but by routing each format through the right processing path before extraction.

Document format is not a pre-processing detail — it is a first-class signal. A scanned PDF and a digitally-native PDF require completely different extraction approaches; treating them identically produces errors that appear random but are systematically format-correlated. The pipeline must know what it is reading before it starts reading it.

Format-Specific Challenges

Each document format introduces distinct extraction challenges. Understanding these challenges at the format level is the prerequisite for building a pipeline that handles them correctly.

.pdf
PDF (Digitally Native)
Text stream exists but may be poorly ordered, with multi-column layouts producing interleaved text. Table structure not preserved in the text layer. Hyperlinks and cross-references lost in text extraction.
.pdf
PDF (Scanned Image)
No text layer — must run OCR on rasterized images. OCR quality depends on scan resolution, alignment, and paper condition. Handwritten annotations not recognized by standard OCR. Font degradation increases error rates.
.docx
Word Documents
Tracked changes embed both versions of text in the document XML. Comments may contain material terms discussed outside the main text. Styles and heading levels exist but require correct parsing to recover structural hierarchy.
.xlsx
Spreadsheets
Contract terms embedded in cells alongside calculations. Implied structure (which rows are header rows, which are data rows) not machine-readable without layout analysis. Cell references may make terms conditional on values in other cells.
.msg
Email Attachments
Contract terms may be distributed across an email thread and its attachments, with material modifications in email body text rather than formal amendment documents. Thread parsing required to establish document and modification sequence.
mixed
Hybrid Documents
PDFs generated from Word documents may have searchable text layers derived from the Word text layer — but the visual appearance may have diverged in conversion. Which layer represents the operative document is not deterministic.

The Five-Stage Extraction Pipeline

01
Format Detection and Routing
Every document entering the pipeline is classified by format, sub-type, and quality characteristics before any extraction attempt. A PDF is classified as digitally native or scanned-image; a Word document is classified as with or without tracked changes; a spreadsheet is classified by its structural role (standalone contract vs. supporting data). Each classification determines the processing path the document follows.
Output: document_type, sub_type, quality_tier, processing_path
02
Format-Specific Pre-Processing
Each format follows its own pre-processing path. Scanned PDFs are deskewed, denoised, and passed to an OCR engine with resolution-appropriate settings. Word documents with tracked changes are resolved to their accepted state (or, if unresolved, both states are extracted separately with a reconciliation step). Spreadsheets are parsed with a layout model that identifies header rows, data regions, and formula cells separately.
Output: clean text with structural metadata, region type annotations, quality confidence scores
03
Semantic Chunking
The clean text is divided into semantic chunks — units that correspond to meaningful structural elements of the document: definitions sections, individual clauses, exhibit content, signature blocks. Chunking at this stage is not for LLM context window management; it is for associating extraction results with source locations that can be cited and audited. A chunk boundary that cuts through a clause produces an extraction that cannot be reliably cited.
Output: clause-level chunks with document position, parent section, and structural role
04
Schema-Constrained Field Extraction
Extraction runs against a defined field schema, with each field's extraction guided by the structural role of the chunk being processed. Governing law is extracted from clauses with a "Governing Law" structural role or from the main agreement body — not from exhibit tables. Liability cap is extracted from clauses with "Limitations of Liability" structural role. Schema constraints reduce false positives from incidental mentions of field-like values in unexpected positions.
Output: structured field-value pairs with source chunk reference, confidence score, and extraction basis
05
Normalization and Validation
Extracted values are normalized to canonical formats (dates to ISO 8601, monetary amounts to a base currency, durations to a canonical unit), then validated against field-level constraints (dates must be valid calendar dates, monetary amounts must be positive numbers, jurisdiction strings must resolve to a known legal jurisdiction). Validation failures and normalization issues generate their own confidence signals — an extracted date that doesn't parse is a low-confidence extraction regardless of source text clarity.
Output: normalized, validated structured data with extraction metadata and confidence scores

Chunking Strategies: Which Works Best for Contracts

The chunking step is where most extraction pipelines make their most consequential design choice. The four common chunking approaches have different strengths and are appropriate for different use cases.

Fixed-Size Chunking
Split the document into chunks of N tokens, with or without overlap. Simple to implement; consistently poor for contract extraction because clauses are not fixed-size and fixed splits cut through clause boundaries systematically.
Not recommended for contracts
Sentence-Level Chunking
Split at sentence boundaries. Better than fixed-size but still problematic — contract clauses are multi-sentence, and splitting at sentence level loses the dependency between sentences within a clause.
Not recommended
Paragraph-Level Chunking
Split at paragraph boundaries. Better alignment with contract structure — most clauses correspond to paragraphs. Does not capture sub-clause structure or hierarchical clause relationships. Acceptable for simple documents; insufficient for complex ones.
Acceptable for simple docs
Semantic Clause Chunking
Use structure detection (section headers, numbering patterns, layout cues) to align chunk boundaries with clause boundaries. The gold standard for contract extraction: chunk boundaries are meaningful, citations are precise, and cross-clause relationships are preserved.
Recommended

A Worked Example: Extracting a Non-Standard Liability Cap

Worked Example
Extracting Liability Cap from a Complex MSA
Document
MSA — 47 pages, digitally native PDF, complex table on page 18
Challenge
Liability cap defined in table as a formula: 2× fees paid in the prior 12 months, subject to a floor of $500K and a ceiling of $10M
Stage 1
Classified as: PDF/digitally-native, table-heavy, clean quality
Stage 2
Table structure preserved; cells extracted as structured data, not linearized text
Stage 3
Chunked as: one chunk for Section 14 (Limitations of Liability) including table reference; one chunk for the table itself with row/column metadata
Stage 4
Schema extraction from table chunk: cap_formula = "2× fees paid prior 12 months", cap_floor = "$500,000", cap_ceiling = "$10,000,000"
Stage 5
Normalized: floor = 500000 USD, ceiling = 10000000 USD. Formula flagged for human review (non-standard format)
Confidence
Ceiling: 0.89 (High). Floor: 0.87 (High). Formula: 0.62 (Moderate — routed for review)

Evaluation: Measuring What Actually Matters

MetricWhat It MeasuresWhy It Matters
Field-level precision% of extracted values that are correctMeasures false positive rate — how many extractions you are acting on that are wrong
Field-level recall% of ground-truth values extractedMeasures false negative rate — how many field values you are missing
CalibrationWhether confidence scores correlate with accuracyMakes confidence scores operationally useful for review routing
Format-stratified accuracyAccuracy broken down by document format and qualityReveals where the pipeline is failing — most failures concentrate in specific format/quality combinations
Citation precision% of extractions where the cited source chunk is correctMakes extractions auditable — if the citation is wrong, the extraction cannot be verified

The Bottom Line

The difference between a contract extraction pipeline that works in production and one that works in a demo is almost always the format handling. Demo documents are clean, native PDFs with standard structure. Production repositories contain scanned archives, negotiated Word documents, embedded spreadsheets, and email-thread amendments. The pipeline that handles only the clean case handles only the minority of the actual portfolio.

Building format-aware extraction requires more investment than building format-agnostic extraction. The payoff is an extraction system whose accuracy on the real portfolio resembles its accuracy on the evaluation set — because the evaluation set was built to reflect the real portfolio, and the pipeline was built to handle what the real portfolio contains.

If your extraction evaluation dataset consists primarily of recent, digitally-native PDF contracts from a single source, your accuracy numbers tell you very little about what the system will do on your full archive. The hardest documents in most real portfolios — scanned archives, Word documents from the early 2000s, spreadsheet-embedded terms — are systematically excluded from vendor benchmark datasets because they are the documents that benchmark scores worst. Test on your data, not theirs.