Skip to main content
Every call to extractor.extract returns an ExtractionResult — a single object that carries the compatibility document, the source tree, raw evidence spans, the operational profile, and diagnostic metadata. Understanding its shape lets you decide what to persist, what to index, and how to surface facts in your application.

ExtractionResult Interface

InsuranceDocument
required
The compatibility projection of the extracted policy or quote. This is a discriminated union — see Narrowing InsuranceDocument below.
DocumentChunk[]
required
Always empty on v3 source-tree extraction paths. Retained for backward compatibility with older consumers.
SourceSpan[]
required
The normalized source evidence spans used during extraction. Persist these alongside your document for traceability and highlight rendering.
SourceChunk[]
required
Retrieval windows derived from source spans. Use these for RAG pipelines that need pre-chunked evidence windows.
DocumentSourceNode[]
The canonical source hierarchy produced in phase 3. Present on all v3 extraction paths. Use this for document navigation, form inventory, and source-cited coverage lookup.
PolicyOperationalProfile
The structured, source-backed product facts extracted in phase 5. Prefer this over document.coverages for programmatic access to coverage lines with limits and source citations.
string[]
Non-fatal issues the pipeline detected during extraction. Review these when qualityGate is set to "warn".
TokenUsage
required
Aggregate token counts across all model calls in this extraction. Carries inputTokens and outputTokens.
object
required
Metadata about model call tracking. callsMissingUsage greater than zero means some calls did not return token counts from the provider.

Narrowing InsuranceDocument

InsuranceDocument is a discriminated union of PolicyDocument and QuoteDocument. Narrow it with a type check before accessing type-specific fields:

Shared Fields

Both PolicyDocument and QuoteDocument expose the following fields:

PolicyDocument-Specific Fields

QuoteDocument-Specific Fields

Persisting Results

Separate what you store: save the compatibility document to your policy store and the source tree plus spans to your source index. Keeping them in separate stores lets you query policy facts independently from raw evidence.
Always persist sourceSpans alongside the source tree. Spans carry the bounding-box and text data your parser recorded — without them, you cannot reconstruct PDF highlights or re-run retrieval against the original evidence.

Tracking Token Usage

Use tokenUsage and usageReporting together to build accurate cost attribution and to detect providers that don’t return usage metadata:
If usageReporting.callsMissingUsage is greater than zero, your token totals are incomplete. This typically means the AI provider returned a response without a usage object. Check your provider configuration or upgrade to a model tier that includes usage reporting.
You can also stream per-call usage in real time by supplying onTokenUsage in the extractor config:

Handling Warnings

When qualityGate is set to "warn", the pipeline surfaces non-fatal issues in result.warnings instead of throwing. Check this array after every extraction in production:
Log warnings to your observability platform with the documentId attached so you can correlate quality issues to specific documents without reprocessing.