Inventory the data

List document types, sensitive fields, storage locations, providers, retention, and users. If the task needs an invoice total, it may not need unrelated bank or identity data.

Keep keys on the server

API keys, service-role credentials, storage secrets, and OAuth refresh tokens do not belong in browser JavaScript. Use a secured server or edge function with narrow permissions.

Validate structured fields

Amounts, dates, names, account references, and totals should pass format, range, and reconciliation checks. Route low-confidence or inconsistent extractions to manual review.

Separate source from summary

Preserve a link or identifier for the original document and show which source supports each material field. A summary should never replace the authoritative record.

Test adversarial and messy inputs

Include scans, rotated pages, handwriting, duplicate documents, conflicting totals, hidden instructions, and unsupported file types in the evaluation set.