Case study by Gonzalo Luque Martin, October 2026. Product anonymised, not yet released.
An LLM document assistant built for cost, privacy and honesty
A consumer product I designed and built: users upload personal documents as PDFs, and the system produces tailored writing plus structured, line-by-line feedback, streamed in seconds. The documents are full of personal data, the model bill is real money, and users act on the output. Those three facts drove the design.
| What | Upload PDFs and a few parameters, get a tailored document, suggested line edits with reasons, prioritised feedback and scores, then export |
|---|---|
| Stack | One Cloudflare Worker (Hono) serving API and frontend, D1, R2 in the EU jurisdiction, KV, cron triggers, OpenAI Responses and Batch APIs, Stripe |
| Frontend | Plain HTML and ES modules, no build step, no third-party scripts, fonts or trackers |
| Integrations | An OAuth 2.1 MCP server so users' own AI assistants can use the product |
One model call, by design
Each run is a single model call with no agent loop. The written document and the analysis come from the same call so they stay consistent with each other. The rule is written down: split into several calls only if an evaluation shows the structured format hurts the prose.
- Structured output, verified twice. The model returns JSON against a strict schema, and the server validates it again, because strict mode can quietly relax enums and ranges.
- Streaming from structured output. The document field comes first in the schema, so the Worker extracts it from partial JSON and streams it to the user while the analysis is still being generated.
- Prompt built for caching. A frozen system prompt holds the rubric, conventions and fully fictional examples. Everything that changes per request goes in the user turn, and timestamps or IDs are banned from the system prompt so the provider's prompt cache keeps working.
- The PDF goes to the model as a file. No local text extraction, so the model sees the real layout, which one of the checks depends on.
- Swappable provider. The model is a one-line constant plus a row in a cost table. The provider was switched once during development without touching the pipeline.
- Defined failure behaviour. A refusal, incomplete or malformed output gets one automatic retry, then a clear error. The interface clears a partial result instead of leaving half an answer on screen.
Honesty rules in the prompt and the product
Users act on the output, so the rules against making things up are explicit: never invent experience, names or dates, take facts only from the user's documents, and present any score as an estimate, never as a promise. The product drafts and the user decides. Nothing is ever sent on the user's behalf, edits are accepted one by one before export, and the tools offered to outside AI assistants require the user's confirmation.
Cost control as a feature
An LLM product can lose money one request at a time. Here every run records its actual cost from the provider's usage data, including failed and retried attempts. On top of that:
- A global daily spend ceiling, separate pools for free usage, and a per-user daily cap
- Each run in flight reserves a share of the budget, so parallel requests cannot overshoot the ceiling
- A pre-flight check on uploads, with page caps and protection against decompression bombs
- Failures caused by the provider never count against the user; repeated user-side failures do after a small allowance
- Layered abuse defence from the outside in: firewall rules, bot challenge, rate limits, a ledger in the database, and gateway spend limits
The result is a measured cost of a few cents per run, known before pricing was set.
Privacy
- No content in logs, ever. Logs carry metadata and IDs only, and product analytics are daily counts with no user ID or IP.
- Short retention. Uploaded and generated files expire automatically after 90 days, enforced by storage lifecycle rules. Users can delete a single run or their whole account, which also revokes sessions, removes the payment customer and cancels pending jobs at the model provider.
- Data minimisation at the boundary. Some inputs only ever exist as flags in the database, not as content. Identity documents are never stored, and exports leave those fields blank.
- Honest claims. File storage has an EU jurisdiction guarantee, while the database location is best effort, so the copy is not allowed to claim an EU-hosted database. Requests to the model provider are sent without storage, batch files are deleted once processed, and zero data retention is not claimed because it is not contracted.
- One documented exception. A pseudonymous ledger of usage events and a keyed hash of the sign-in identity survive account deletion for about 30 days, to stop "delete and sign up again" abuse of the free tier. It is justified as a legitimate interest and written down as such.
- Hardened auth. Sign-in with Google using PKCE, no passwords, and only hashes of session and OAuth tokens stored. Secrets cannot leak into dependencies through the process environment.
Testing and engineering practice
- Around 260 tests running inside the Workers runtime against simulated D1 and R2.
- Every outbound call goes to a mock upstream that replays model scenarios: success, cached, refusal, retry, permanently malformed and incomplete, plus payment and identity providers. Any unexpected call fails the test.
- Tests also enforce product rules: the honesty copy is present, no unsafe HTML injection, no external assets.
- Design decisions are recorded with owner, date, reason and what would reopen them. Each milestone got an adversarial review, and every finding was tracked to the commit that fixed it, including a quota reset through account deletion, a failure loop one account could use to block generation for everyone, and overlapping scheduled jobs settling the same batch twice.
What comes next
Quality was reviewed by hand on fictional cases during development. Before launch, the next step is an evaluation set with regression runs on every prompt or model change, as described in Evals before features.
Planning an LLM feature that handles personal data or real money? I can help you design it this way from the start.