Turning government mail into structured data
An LLM pipeline that ingests IRS and state correspondence arriving as scanned paper and inbound fax, identifies what each letter is, works out which company it belongs to, and puts it on that customer's dashboard. Around 50 letters a day.
The problem
The IRS publishes no API and fires no webhooks. Its correspondence reaches a company formation business the same way it reaches everyone else: as physical mail and as fax. Neither carries any metadata about which of thousands of registered entities it concerns, and a compliance deadline missed because a notice sat unread is a real cost to a real customer.
Getting the documents in
Physical mail was the tractable half. Letters arrive at a mailbox address, the provider opens the envelope, scans the contents and posts them to a webhook.
Fax had no such path. The fax provider offered no webhook at all. What it did offer was the ability to forward every received fax to an email address, so I chained two providers into the integration that neither one shipped: I stood up an inbound mail server on Postmark, pointed the fax provider's forwarding rule at it, and consumed Postmark's inbound webhook. Fax provider to email, email to Postmark, Postmark to us. From that point both channels are the same document on the same queue.
Making sense of them
The unified flow calls Gemini with a purpose built prompt that first decides whether the document is government correspondence at all, because bank letters and unrelated post arrive through the same mailbox and have to be dropped rather than misfiled. For anything that is, the model extracts the letter type, the notice code, the entity it addresses and the specific mailbox it landed in. That gets matched against internal records, attached to the right company, and surfaced on the customer's dashboard for download.
- Node.js
- Google Gemini
- Postmark inbound
- Webhooks
- PostgreSQL
- Document classification