Pipeline Phases
1
Normalize Source Spans
Merge Docling-derived and caller-provided spans, then normalize their text. This phase reconciles overlapping or duplicate spans from different parsers into a single, deduplicated span set.
2
Persist Source Evidence
If a
sourceStore is configured on the extractor, this phase saves the normalized spans and chunks before any extraction begins. Persisting evidence early means you retain raw source data even if a later phase fails.3
Build the Source Tree
buildDocumentSourceTree() converts the flat SourceSpan[] into a hierarchy of DocumentSourceNode[]. Each node carries one of the following kinds:4
Group Source Structure
Source nodes are grouped into declarations, policy forms, endorsements, sections, and schedules based on source text and parser-derived titles. Three hard constraints apply during grouping:
- Don’t invent IDs — every node ID must derive from the source
- Keep separately-numbered endorsements separate — don’t merge endorsements that carry distinct form numbers
- Keep titles terse — use the source heading text verbatim; don’t rephrase
5
Extract the Operational Profile
A single
generateObject call with bounded evidence extracts the full PolicyOperationalProfile. Every extracted fact must cite either sourceNodeIds or sourceSpanIds. This phase produces:policyTypesaslinesOfBusinessACORD codes- Policy number, named insured, insurer, and broker
- Effective and expiration dates
- Total premium
- Coverage units with structured limits
- Endorsement inventory and support flags
6
Clean Up Coverage Units
An optional bounded cleanup pass reconciles coverage units — merging duplicate lines, filling missing fields, and resolving ambiguous references. You can control this pass via
modelCapabilitiesByTaskKind.7
Project Compatibility Output
The final phase materializes the
document, documentMetadata, and documentOutline views from the operational profile and source tree. These are backward-compatible projections that conform to the InsuranceDocument schema.Quick Start
The snippet below shows the minimal setup to run the extraction pipeline against a base64-encoded PDF:PDF inputs require
ExtractOptions.sourceSpans. You must parse the PDF with LiteParse, Docling, PDF.js, OCR, or another parser before calling extractor.extract. The pipeline does not perform its own PDF rendering.Docling Input
If you parsed your document with Docling, pass the JSON document object directly instead of a base64 string:Extractor Configuration
Create an extractor withcreateExtractor, passing an ExtractorConfig object. Only generateObject is required; all other fields are optional.
GenerateObject
required
Your AI provider wrapper. The pipeline calls this function for each structured generation step.
(usage: TokenUsage) => void
Called after each model call with incremental token counts. Use this for real-time cost tracking.
(message: string) => void
Receives human-readable status messages as the pipeline advances through phases. Useful for streaming progress to a UI.
SourceStore
If provided, the pipeline persists source spans and chunks in phase 2 before extraction begins.
"off" | "warn" | "strict"
Controls how the pipeline responds to low-confidence extractions.
"strict" throws on quality failures; "warn" logs them; "off" suppresses all quality checks.Partial<Record<ModelTaskKind, ModelCapabilities>>
Override model capabilities per pipeline task. Use this to allocate larger output budgets to specific phases.
Model Routing Example
Route different token budgets to the operational profile extraction and the optional coverage cleanup pass:Progress Messages
When you supplyonProgress, the pipeline emits the following messages at key phase boundaries: