A working LLM document pipeline has six stages: classify the document, extract its text, split it into chunks, pull structured fields against a fixed schema, validate every output, and route low-confidence results to a human. Two rules matter most: use deterministic code wherever it works, and treat validation as a first-class stage, not a final filter. Here is each stage, the decisions inside it, and a worked example.
The six stages
1. Intake and classification. Identify the document type before anything else runs, because every downstream choice - schema, chunking, review threshold - depends on it. A classifier that is 95% accurate still feeds one document in twenty into the wrong schema, so log misroutes. AI Document Classification for Business covers an intake workflow.
2. Text extraction. Digitally born PDFs give you text directly; scans and photos need OCR first. Preserve page numbers and reading order - reviewers will need them to trace any field back to its source page.
3. Chunking. For contracts and long documents, split on structure (clauses, sections, table boundaries), not fixed token windows. A clause cut mid-sentence produces fields you cannot verify.
4. Structured extraction. Prompt against a strict, versioned JSON schema per document type, and require an evidence span quoting the source text for every field. The evidence quote is the cheapest accuracy improvement available. See Prompt Engineering for Structured JSON Output and Contract Metadata Extraction Methods for field selection.
5. Validation. Two layers: schema validation (types, required fields, date formats) and business rules (end date after start date, totals equal line items, party names match the cover page). Deterministic checks catch more errors than a second LLM pass, and they cost nothing.
6. Human review. Route by confidence threshold, not random sampling. Reviewer corrections become your regression test set.
Key choices per stage
| Stage | Choice | Pick when | Trade-off |
|---|---|---|---|
| OCR | Managed API | Mixed scans, low volume | Per-page cost at scale |
| OCR | Self-hosted | High volume or residency needs | Ops burden, tuning |
| Chunking | Structural | Contracts, legal docs | Needs a reliable parser |
| Extraction | One call per document | Short docs, few fields | Long docs hit context limits |
| Extraction | Per-section calls | 10+ pages, many fields | More calls, more cost |
| Review | Threshold routing | Any real volume | Needs calibrated confidence |
Worked example (hypothetical)
A 12-page vendor agreement arrives. It is classified as "vendor agreement"; OCR is skipped because the PDF is digital; structural chunking yields 41 clauses. The schema asks for 11 fields: parties, effective date, term, renewal clause, notice period, payment terms, liability cap, governing law, and three more. Validation passes most fields; three fall below the confidence threshold because the liability cap is stated differently in two clauses. A human reviews three fields instead of the whole document. That is the point of the design: reviewer time goes only where the pipeline is unsure.
Trade-offs and limits
- OCR errors propagate silently. A misread date becomes a wrong renewal reminder. Spot-check OCR output on scans.
- Per-section extraction raises accuracy but multiplies call count. Measure cost per document at your real volume before committing.
- Confidence scores are not calibrated out of the box. Set thresholds from your labeled test set, not intuition.
- Without 50-100 real labeled documents, you cannot detect regressions when prompts or schemas change.
Pre-launch checklist
- [ ] 50-100 labeled documents per type, including messy scans
- [ ] Versioned JSON schema with an evidence-quote field
- [ ] Deterministic rules for dates, totals, and party names
- [ ] Confidence thresholds set per field criticality
- [ ] Review queue that captures corrections as test data
- [ ] Regression evals run on every prompt or schema change
- [ ] Cost per document measured at target volume
If document pipelines are not your core product, this is the job ZiaSign's AI contracts team already does: it reads scanned PDFs through OCR, summarises agreements, extracts obligations and flags risk, with a REST API and signed webhooks if you want results inside your own systems.
Next step: pick one document type, label 30 examples by hand, and see how far a single schema-plus-validation pass gets you before adding anything else.
From the Zettaura team: ZiaSign puts nine AI employees on your contracts - review, extraction, renewals and signing in one workspace. See how it works at ziasign.com.



