Inspiration

Every frightening letter asks the same two questions and answers neither of them in its first paragraph. A water shutoff notice. An Explanation of Benefits whose opening line is THIS IS NOT A BILL. A jury summons. A tax "proposed change". The thing you actually need to know is one sentence long, and it is buried in a page of defensive prose written by somebody's legal department.

Do I have to do anything, and by when?

That is a perfect job for a language model. It is also a terrible thing to upload. A water bill carries your name, your address and your account number. An EOB carries your health. And the people who most need help with this mail — someone reading in a second language, someone handling their parents' post — are precisely the people who should not be pasting it into a chatbot.

So the interesting constraint was never can a model explain this letter. It was:

Can it explain this letter without the letter leaving the phone?

Hybrid inference is what makes the answer yes for most documents, and honest for the rest.

What it does

Snap a letter, bill or form — document scanner, photo, or PDF. Paperwork Decoder hands back a card with five parts: what this document is, a plain-language summary, what you need to do (with amounts and dates), what happens if you ignore it, and what's worth double-checking — the model's own account of what it wasn't sure about. Then it offers to put each deadline in Reminders, and lets you ask follow-up questions about the document.

Short documents are decoded entirely on the iPhone: the photo, the text and the answer never leave it.

A ten-page lease doesn't fit on the phone, and a phone without Apple Intelligence can't do any of it. Rather than quietly uploading what doesn't fit, the app:

  1. redacts the personal details on the device,
  2. shows you the exact text that would be sent — scrollable, in full, not a summary of it, with the counts of what was blacked out,
  3. sends nothing until you tap,
  4. and puts your real values back on the device, so the answer reads naturally even though the cloud model never saw them.

Every card carries a badge naming the model that answered, read from response.rawResponse.modelVersion — never hard-coded, never inferred. You can always tell which engine you got.

How we built it

SwiftUI, iOS 26, Swift 6 toolchain. Firebase AI Logic supplies both engines through one SDK: the on-device session is Apple Foundation Models, and the cloud-capable session is .hybridModel(primary: systemModel, secondary: cloudModel) — so even the cloud path tries the phone first. Structured output on both legs via @Generable, so a decoded card is a typed DecodedDocument rather than prose to be regex'd. Firebase App Check (App Attest) guards every cloud call, and Firebase Remote Config carries the routing threshold, the cloud model name, the prompt version and an enable_cloud kill switch, so the privacy posture can be tightened after shipping without waiting on a release.

The routing is arithmetic, not a vibe. We didn't want a heuristic deciding where a private document goes, so the decision is a subtraction the app will show you on screen. The on-device context window $W$ is read at runtime from SystemLanguageModel.default.contextSize — 8,192 tokens on iOS 27.2, 4,096 below — and what a document has to fit into is what's left after reserving room for the instructions and for the answer:

$$B_{\text{doc}} \;=\; \max\bigl(0,\; W - R_{\text{instr}} - R_{\text{out}}\bigr) \;=\; 8192 - 400 - 1200 \;=\; 6592$$

Document size is estimated deliberately high, because the failure mode of guessing low is an overflow halfway through a decode:

$$\hat{t}(n) = \left\lceil \tfrac{n}{3.5} \right\rceil \qquad \text{measured: } \approx 4.3 \text{ chars/token, so } \hat{t} \text{ runs } \sim 20\% \text{ over}$$

Run our six sample documents through that and the split falls out on its own. The water shutoff notice is ~360 tokens: it stays on the phone. The ten-page residential lease is ~15,700 against a 6,592-token budget: it cannot, not by a near miss but by a factor of two and a half. The tax notice is ~3,400 — so it decodes on the phone on iOS 27.2 and needs the cloud on iOS 26, from the same tap. That document is in the sample set precisely because it crosses the line.

A conversation is tighter still ($W - 600 - 500 - 900$, since the earlier turns and your question have to fit beside the document), which produces a state we didn't anticipate and now rather like: a document can be short enough to decode on your iPhone and still be too long to chat about there.

The rest of the pipeline is all on-device by construction. Capture is VisionKit's document scanner, Vision for OCR, PDFKit for digital PDFs — the image never leaves the phone, and the on-device model couldn't accept an image anyway. Redaction is NSDataDetector plus hand-written detectors for social-security, account, card and routing numbers and links — nine kinds in all — producing stable typed tokens ([NAME_1], [ACCOUNT_1]) that are mapped back locally. Deadlines go to EventKit, and the reminder's note carries the document's own wording, never its content. History is SwiftData in a container created without a CloudKit configuration, on purpose. Nothing is logged to analytics or crash reporting. There is no server-side copy of anything.

One rule governs the whole app: raw document text is only ever handed to the on-device-only session. There are exactly two places in the codebase where a document reaches a model — raw text to .onDeviceOnly, redacted text to .hybrid — and a spy engine in the test suite fails the build if the short-document path gets anything but the unredacted letter, if anything else gets raw text, or if any model is called before consent returns.

(The demo video's narration is AI-generated — Kokoro-82M, run locally.)

Challenges we ran into

The date we got wrong in the most dangerous way. A notice saying "within 10 days of the date of this notice" was being counted from the day you scanned it. Decode a letter two weeks after it arrives and the app would cheerfully set your reminder after the deadline it existed to protect — 15 days late, on one of our own samples, with total confidence. The fix was to take the arithmetic away from the model entirely: ask it for the document's own date and the deadline exactly as written, do the counting on device, then tell the user which reading was used ("counted as 10 days from the document's own date, Nov 18, 2026"). A wrong answer is now visibly wrong instead of silently wrong.

Teaching it to refuse. "Within 90 days after a final assessment" counts from an event that hasn't happened and isn't dated anywhere on the page. The app used to produce a confident date for it; now it says it can't read one. NSDataDetector also happily resolved "the second Monday in January" to a Monday in November — right weekday, wrong month, wrong year — so a detected date is now rejected outright if its month isn't one the text actually names. The tests that matter most are the ones asserting which phrasings the parser must decline.

Checking the redactor instead of trusting it. Nobody reads ten pages of redacted lease by eye, so ResidualScan re-runs the detectors over the already-redacted text and shows, on the consent screen itself, what they still find. It is a check on the redactor's output, not a proof — it runs the same detectors, so what they both miss stays missed. The screen says exactly that, and still asks you to read the text yourself.

The consent screen was the hardest writing in the project. The first version said "Send this text" above a wall of lease. Testers couldn't tell what they were agreeing to or what they'd get back. It now asks a question about the outcome — Explain this with Google Gemini? — and then says, in order, what happens: blacked out on this iPhone (with the counts), the rest goes to Gemini, your explanation comes back here. Same bytes, same guarantee, and people finally understood the trade they were being offered.

The Simulator can't do the central thing. It reports Apple Intelligence as available and has no on-device safety model, so a real on-device decode cannot be observed there at all. Every on-device behaviour had to be built against tests and a fake engine instead of against something we could watch.

Accomplishments that we're proud of

The app tells you what it doesn't know. The Worth double-checking section, the badge naming the model, the sentence explaining where a date came from, the refusal to invent a deadline it can't derive — all of it points the same way. A tool for frightening documents should be legible about its own reasoning, not merely confident.

The privacy claim is checkable, not rhetorical. Raw text has exactly two routes out of the capture layer; 253 tests hold the line, including a spy engine that fails the build if any model is called before consent, the redactor run against all six samples, the router's budget arithmetic, and the deadline phrasings the parser is expected to refuse.

The routing is on screen. A user who wants to know why their lease needs the cloud can read the numbers that decided it, with the Remote Config values behind them — and a phone that can't run Apple Intelligence gets a different first step, not a worse product.

What we learned

Hybrid isn't a fallback. Framing it as "on-device, with cloud if needed" misses what it actually buys. The cloud leg is what makes the private path affordable to offer at all: without it, a ten-page lease means either refusing the user or quietly uploading their lease. With it, the expensive document gets an explicit, informed choice — and the cheap document never leaves the phone. That's a product decision the SDK made possible, not a deployment detail.

The model is the wrong place for arithmetic. Every date bug we had came from asking a language model to compute rather than to read. Ask it to extract; do the maths yourself; show your work.

A test can hold a line the compiler can't. "No raw text to a cloud-capable session" isn't expressible in Swift's type system here, so it's a spy engine and a named invariant instead — and the honest thing is to say that out loud rather than call it structurally impossible.

What's next for Paperwork Decoder

First, the thing we owe you plainly: on-device generation has never been run on physical hardware. The Simulator cannot do it and the device session hasn't happened yet. The path is implemented, routed, badged and tested — it has not been watched working, so nothing in the demo claims it has: the video shows routing, redaction and consent, and the one decoded card in it is explicitly a canned answer. The current prompt has also never faced a real model, so card quality is unproven. DecodeQuality already scores cards against rules read off the sample documents — a redaction placeholder that was never restored, a deadline the parser can't read, an urgency contradicting a date on the page, the EOB being read as a bill — ready for output that doesn't exist yet. That gap is written up in the README and in docs/DEVICE-PASS.md as a checklist, because a tool whose whole argument is tell the user what you don't know doesn't get an exception for itself.

So: the hardware pass, and the prompt tuning it unblocks. Then batch-decoding a stack of mail, an iPad layout, and explaining a document in a language other than the one it was written in — the feature this app most wants, and the hardest one to do without sending text away.

Built With

  • apple-foundation-models
  • apple-intelligence
  • eventkit
  • firebase
  • firebase-ai-logic
  • firebase-app-check
  • firebase-remote-config
  • gemini
  • hybrid-inference
  • ios
  • ios26
  • nsdatadetector
  • ocr
  • on-device-ai
  • pdfkit
  • privacy-by-design
  • swift
  • swift-testing
  • swiftdata
  • swiftui
  • vision
  • visionkit
  • xcode
  • xcodegen
Share this project:

Updates

Submission history