Extract and Validate Insurance Claim Packets With Python
Classify a mixed insurance claim packet, extract each document with its own schema, and flag conflicting identifiers, dates, and missing fields for review.


A claim packet arrives as one PDF: a first notice of loss, policy declarations, a two-page repair estimate, a police report, and a rental invoice. The estimate carries a different policy number from the declarations. The police report gives a different loss date. Extracting everything into one JSON object can hide those disagreements by leaving only one value for each field.
This guide builds a Python workflow that keeps each document's values separate, compares them, and produces a review list with source pages. Unsiloed handles page classification and schema-based extraction; Python handles document grouping, identifier checks, and routing. The output helps a person investigate a packet. It does not decide coverage, liability, or payment.
Download the example project and the six-page sample packet. The project includes the fixture generator, schemas, saved API responses, consistency checks, and tests. You need Python 3.10 or later and an Unsiloed API key for a new extraction. You can replay the saved responses without a key.
What the Claim Packet Workflow Returns
We tested the workflow on a synthetic auto-claim packet. Its five documents deliberately contain three problems:
| Document | Packet Pages | Detail to Check |
|---|---|---|
| First notice of loss | 1 | Policy PAP-7781-2209; loss date 09/14/2026 |
| Policy declarations | 2 | Policy PAP-7781-2209 |
| Repair estimate | 3–4 | Policy PAP-7781-2290 |
| Police report | 5 | Collision date 09/13/2026 |
| Rental invoice | 6 | Claim number left blank |
In the completed run, Unsiloed classified all six pages into the expected categories and extracted all five documents. The checks found all three planted problems. They also flagged an extracted page label without a citation and held the policy-period check for review until the conflicting dates are resolved. The final route was reviewer_queue, with five open findings.
That is one packet, not a measurement of accuracy across insurers or document formats. The fixture is a text-bearing PDF with readable headings. It does not test handwriting, damaged scans, handwritten amendments, or claim files containing hundreds of pages.

The distinction from insurance policy extraction is the unit of work: we compare evidence across several documents rather than extract one policy. A loss-run extraction workflow addresses a different task, collecting claim histories from reports. Here we preserve disagreements inside one submitted claim packet.
Run the Python Example
Extract the ZIP, enter its claim-packet directory, and create a virtual environment:
python3 -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txt
python -m pytest -q
The example uses requests for the API, pypdf for page handling, and reportlab to generate the fixture. The tests run locally against recorded responses and controlled error cases. They do not submit API jobs.
First replay the completed run:
python run_pipeline.py --checks-only --out output-run-3
Open output-run-3/review.md for the readable findings and review.json for the structured result. The saved raw responses remain under output-run-3/raw/, separate from the checks derived from them.
To process the sample again, set your key and use a new output directory:
export UNSILOED_API_KEY="your-api-key"
python run_pipeline.py fixtures/claim-packet.pdf --out my-run --max-wait 600
This makes six classification requests and five extraction requests, processed sequentially. Each extraction uses model=gamma and enable_citations=true. A new run consumes API usage and can produce different scores or citations. The 600-second setting is a polling budget for each job, not a deadline for the whole packet; individual HTTP requests also have a 60-second timeout.
Classify Pages Before Choosing a Schema
The classification API takes a document and named candidate categories. The project defines its categories in schemas.py:
CATEGORIES = [
"first_notice_of_loss",
"policy_declarations",
"repair_estimate",
"police_report",
"rental_invoice",
"other",
]
The client uploads each page separately to POST /classify, then polls GET /classify/{job_id}. It sends categories as a JSON array of objects such as {"name": "repair_estimate"}. This keeps the packet-to-page mapping explicit and lets one failed page become a review item while the other pages continue.
The API accepts multi-page files, but its current reference says documents longer than four pages are classified from their first four pages. This example sends individual pages to cover all six pages explicitly. It reads each returned label and confidence, then groups adjacent pages with the same label. Pages three and four become document D3, a repair estimate spanning packet pages 3–4.
The grouping function in packet.py only joins a page when its label matches the preceding document and neither has a review reason:
if (previous and item["reason"] is None
and previous["review_reason"] is None
and previous["type"] == item["label"]
and previous["pages"][1] == item["page"] - 1):
previous["pages"][1] = item["page"]
previous["page_confidence"].append(item["confidence"])
A classification confidence below 0.80 prevents automatic grouping and extraction for that page. That cutoff is an example setting, not a calibrated probability of correctness. Test thresholds against labeled documents from your intake process. The guide to classification confidence scores explains the routing tradeoff.
Grouping by adjacent label has a specific limit: two estimates placed next to each other would merge into one document. Before adapting this to unrestricted intake, add document-boundary checks using estimate identifiers, printed page labels, or confirmed page ranges. The sample does not call Unsiloed's splitting endpoint, and it does not establish that this grouping rule handles arbitrary packets.
Extract Each Document With Its Own Schema
A policy declaration and a repair estimate need different fields. Keeping their schemas separate also makes it possible to retain two different policy numbers instead of asking a model to reconcile them.
In schemas.py, the repair-estimate schema requests its printed identifiers, every line item, totals, and page labels. Its line-item portion is:
"line_items": {
"type": "array",
"description": "Every estimate line item on every page, in printed order. "
"Exclude subtotal, tax and total rows.",
"items": obj({
"description": field("string", "Line item description"),
"amount": field("number", "Line item amount in USD"),
}),
},
The complete schemas are in the download. Identifier descriptions ask for the value as printed, including dashes, and ask for null when absent. The code preserves the returned raw values and performs normalization separately. It does not manufacture a missing claim number from another document.
The client in unsiloed_client.py submits each document range to the extraction endpoint:
files = {"pdf_file": (filename, pdf_bytes, "application/pdf")}
data = {
"schema_data": json.dumps(schema),
"model": "gamma",
"enable_citations": "true",
}
job_id = self._submit("/v2/extract", files, data)
return self._poll(f"/extract/{job_id}", job_id)
Citations are optional and disabled by default, so the flag matters. In the saved response, the estimate's policy number is:
{
"value": "PAP-7781-2290",
"score": {
"grounding_score": 0.98,
"extraction_score": 0.99
},
"citation": {
"bbox": [220, 154, 305, 169],
"page": 1,
"page_width": 612.0,
"page_height": 792.0
}
}
The extraction score describes confidence in the extracted value. The grounding score describes confidence that the value was located in the document. Neither establishes that a policy number is the correct number for the claim. Here, a confidently extracted number disagrees with the other documents, which is exactly why the consistency check runs after extraction.
Map Citations Back to the Original Packet
The estimate is submitted as a two-page PDF. A citation on its second page refers to page two of that submitted document, which is page four of the original packet.
The mapping in packet.py is:
packet_page = first + int(citation_page) - 1
if not first <= packet_page <= last:
raise ValueError("Citation page is outside the document")
Each review finding retains the document ID, raw value, normalized comparison value, packet page, bounding box, and scores. A review UI can use the packet page to open the original PDF and the box to highlight the cited region. The example produces JSON and Markdown; it does not include that UI.
A missing field has no location to highlight. The rental invoice's blank claim number returned value: null, an extraction score of 0.98, and no citation. Its document range tells us which invoice to inspect, but we do not invent a field-level box or page citation. The check reports the missing claim number even though the extraction score is high.
The completed run also returned Page 2 of 2 without a citation, with a grounding score of zero. The printed label was correct when checked against the fixture, but the citation check still flagged it. Preserve this distinction: a value can be correct yet lack the source coordinates your review process requires.
Compare Identifiers, Dates, and Amounts
The checks in checks.py are deterministic Python. Unsiloed supplies the document fields; your application defines which documents must agree and which missing values need attention.
The example compares:
- Claim numbers across the notice, estimate, and rental invoice
- Policy numbers across the notice, declarations, estimate, and rental invoice
- Vehicle identification numbers across the notice, declarations, estimate, and police report
- Police-report numbers across the notice and report
- Loss dates across the notice and police report
- Estimate line amounts, subtotal, tax, total, and printed page sequence
Identifiers are uppercased and have whitespace removed. Dashes remain significant. Dates are parsed into ISO format while retaining the source strings. For this fixture, the date formats are unambiguous U.S. dates; add explicit locale handling before accepting documents with ambiguous day/month order.
The policy-number check builds a set of nonblank normalized values. More than one value creates a conflict. It retains every contributing document rather than taking a majority vote or replacing the estimate's number with the declarations' number.

The final review contains these open items:
| Status | Check | Finding |
|---|---|---|
| Conflict | Policy number | PAP-7781-2290 on the estimate differs from PAP-7781-2209 on the other three documents |
| Conflict | Loss date | Notice says September 14; police report says September 13 |
| Missing | Claim number | Rental invoice has no claim number |
| Review | Loss date in policy period | Resolve the conflicting dates before checking the period |
| Review | Source citations | The second estimate page label has no citation |
The six estimate line amounts sum to $2,053.65; adding $84.16 tax gives the printed $2,137.81 total. Those arithmetic checks pass. They establish agreement among extracted amounts, not that the repair charges are reasonable or payable. For production currency calculations, use decimal amounts or integer cents rather than the example's floating-point arithmetic.
The required-document list is specific to this demonstration. A police report is not universally required for every claim. Configure it for the claim type and your intake rules. Likewise, a date inside a printed policy period does not establish coverage. Endorsements, exclusions, applicable terms, and the facts of the loss still need assessment.
Keep Failures and Incomplete Evidence in Review
A partial extraction must not create a false pass. In an earlier run, the estimate exceeded a 300-second polling budget. Because it was the document carrying the mismatched policy number, comparing only the remaining documents could have hidden the conflict. The example now marks affected comparisons for review when a classified document has no extraction.
The client stops on failed or review job states and saves error context. A polling timeout retains the job ID and polling path. Poll that existing job again using client.resume(poll_path, job_id) rather than submitting the PDF a second time. The CLI saves the timeout details in the corresponding raw/*-error.json; automatic resumption across the full packet is not implemented.
For explicit 429 or 503 responses, the client waits before retrying within a fixed attempt limit, following Unsiloed's capacity and backpressure guidance. A transport timeout during submission is different: the server might have accepted the request. The client stops with an unknown-outcome error so you can inspect jobs before resubmitting. Polling transport errors keep the existing job reference.
The example flags nonblank fields with missing citation data, extraction scores below 0.90, or grounding scores below 0.80. These are demonstration thresholds. Calibrate them with reviewed packets; a high score cannot replace missing-document checks or cross-document comparisons.
The local suite covers the recorded outputs, page mapping, missing evidence, conflicting dates, arithmetic changes, classification thresholds, rejected submissions, polling limits, and transport failures. It passed 41 tests. The failure responses are controlled test cases; the live exercise did not induce every API error state.
Adapt the Workflow to Your Claim Intake
Start by keeping the original packet and an immutable record of its document ranges. Add claim-type-specific schemas and explicit boundary rules before widening the accepted document set. Keep extracted evidence separate from reviewer corrections, and record the reason for a correction instead of overwriting the raw response.
Before using policyholder documents, configure storage access, retention, and logging for the data your organization handles. This sample uses fictional names and identifiers and writes its responses to local files. It is a development example, not a claims system with access controls, retention enforcement, or an audit interface.
Unsiloed provides the classification, typed extraction, confidence scores, and optional source coordinates that this workflow needs. Your application can then apply explicit consistency rules and give reviewers a shorter list of disagreements to investigate. Create an Unsiloed account, run the sample, and adapt the schemas and review rules to a labeled set of your own claim documents.



