Work I’ve done

Documents · US mortgage lender, via Amihan Solutions

Document review where rules check the facts first

An AI review tool that starts when an appraisal is received in Encompass, checks the facts with fixed rules before and after the AI, and puts a structured verdict and findings in the underwriter’s queue. I was the lead engineer on its review engine and built its event-driven intake.

  • Used in production by the lender’s underwriting team
  • About 70 rule checks around every AI review

1 · Checking the facts

Facts checked by rules, not guessed by AI

Each fact was pulled from the form and checked by fixed rules. AI drafted the verdict from the checked facts only. A person decided.

1 · Reads the appraisal

Each fact is pulled from its place on the form

Appraisal report

Form fields

Property
14 Marlow Street
Appraiser
Sam Ortega
Signed
12 Mar 2026
Appraised value
$412,000

Checkboxes

  • As is
  • Subject to repairs

Table · Comparable sales

22 Marlow Street
$405,000
9 Alder Avenue
$418,000
31 Pine Road
$409,000

Comparable photos

2 · Checks the facts

Fixed rules, the same for every appraisal

  • Signed by the appraiser
  • Appraiser’s licence valid on the effective date
  • Effective date under 120 days old
  • Comparable photos present1 of 3 missingFlagged
  • Net adjustments under 15%
  • Gross adjustments under 25%
  • CDA value within tolerance

3 · Drafts a verdict

AI, working only from the checked facts

  • Pass
  • Conditional
  • Reject

Reason

One comparable photo is missing. Every other check passed.

Underwriter confirms

One appraisal, from document to decision · Illustration, not a real appraisal
The cost
Underwriters read every property appraisal by hand. Each one mixes forms, tables, checkboxes and photos, and the same facts had to be found and checked in every one.
The first attempt
An earlier approach fed the AI hundreds of document chunks at once, and even basic facts could not be relied on.
What I rebuilt
Facts are extracted in code wherever possible. About 20 checks run before the AI and about 50 after it; when code and the AI disagree, code wins, and a second model re-verifies each finding.
Result
Every review has the same validated structure, so underwriters spend their time on judgement calls, not on re-checking routine facts.
Technical detail

Extraction is layered: PyMuPDF reads fields from label positions, form widgets and the sales grid; scanned pages fall back to OCR, and flattened PDFs to Google Document AI Form Parser. Photos, scanned pages and sales grids are analysed by a vision model in parallel under a concurrency limit, and supporting documents (CDA, AVM, UCDP, BPO) are parsed and cached by document hash. Retrieval uses Pinecone, with predefined semantic queries selected by rules from the checks’ findings rather than sending every chunk to the model. The main model (OpenAI GPT-4.1, with Anthropic Claude as a switchable provider) returns structured JSON validated against a Pydantic schema.

2 · Starting by itself

A report waiting before anyone asks

Nobody had to start it. The report was waiting in the underwriter’s queue.

1 · Appraisal received

An “Appraisal Received” milestone in Encompass

Encompass · Loan file

14 Marlow Street

Loan 20418

  • Appraisal reportSubmitted
  • Purchase contractOn file
  • Title reportOn file

2 · Triggered

The submission starts the tool. Nobody asks

Runs by itself

  • Webhook received
  • Signature verified
  • Duplicate event dropped
  • Milestone confirmed with Encompass
  • Review run
  • Saved and assigned to the underwriter

3 · In the queue

Waiting when the underwriter opens it

Review queue

4 ready

  • 14 Marlow Street1 photo missingConditional
  • 8 Harbor LaneAll checks passedPass
  • 51 Quarry RoadValue outside comparable salesReject
  • 3 Linden CourtAll checks passedPass

Underwriter opens and confirms

One loan, from submission to queue · Illustration, not a real loan file or queue
The cost
Reviews started only when someone triggered them, through a client-side script.
The trigger
Encompass sends a webhook when an appraisal is received. That became the signal to start.
What I built
A webhook endpoint that verifies the signature, drops duplicate events and confirms the live milestone before starting a review. I then retired the old script.
Result
The review is already in the underwriter’s queue when they open it.
Technical detail

The endpoint checks the HMAC signature, validates the payload, keeps only the “Appraisal Received” milestone, drops repeated event IDs, and confirms the milestone and loan number through Encompass’s Field Reader API. It always acknowledges, because Encompass deletes a subscription that returns server errors. The review runs in the background; results are saved to PostgreSQL, assigned to the loan’s underwriter, and listed by a queue API that shows the latest review per loan using a window function, with filters, search, pagination and severity counts.

3 · When things go wrong

Failures recorded, never dropped

Review history

14 Marlow Street · Loan 20418

  • Review 1Failed · reason classified · audit entry savedFailed
  • Review 2Next trigger retried itCompleted
One loan’s review history · Illustration, not a real loan file
Duplicate events
Encompass can send the same milestone twice. The webhook drops repeated event IDs, and a teammate’s database lock keeps one active review per loan.
A failed run
It is saved as a failed review with a classified reason and an audit entry, and the next trigger can retry it.
Visibility
Webhook results, engine outcomes and review time go to Prometheus, with a Grafana dashboard I built.
Result
Failures leave a record, never a silent gap.

4 · What I built and why

My part, and the decisions behind it

I built

  • The Encompass webhook intake, and retiring the old script trigger
  • The engine’s layered extraction, supporting-document handling and targeted retrieval
  • The engine adapter, result persistence, underwriter auto-assignment and the queue API
  • Prometheus metrics, the Grafana dashboard and production Terraform changes for the webhook and Form Parser

Teammates built

  • The database dedup lock, schema migrations, the real-time queue push, queue KPIs, access control and the front-end
Code wins
Rules run before and after the AI, and deterministic values override it, because the AI alone was unreliable on facts.
Rules pick retrieval
Predefined queries chosen by rules are predictable, cheaper and easy to debug.
Fallbacks
Text layer first, then OCR, then Form Parser, so one bad document type doesn’t break a review.
A safe webhook
Always acknowledge, verify the signature, and confirm the milestone before acting.

Built with

  • Python
  • FastAPI
  • OpenAI SDK
  • Anthropic Claude SDK
  • LangChain
  • Pinecone
  • PostgreSQL
  • Firestore
  • Google Document AI
  • PyMuPDF
  • Pydantic
  • Cloud Run
  • Terraform
  • Prometheus
  • Grafana

What this means for a small team

The same pattern fits any team that reads documents and types the details into another system: invoices, application forms, client intake. Each detail is pulled out and checked by fixed rules first, AI drafts a summary from the checked facts, and a person approves the result.

See what you could automate

Enter your website and get three workflows worth automating, with estimated hours saved.

Next case studySupport tickets sorted, routed and answered faster