DEV Community

Cover image for I built an AI agent that turns Gmail receipts into a spreadsheet — automatically
John Dreic
John Dreic

Posted on • Originally published at contextgate.ai

I built an AI agent that turns Gmail receipts into a spreadsheet — automatically

Are you sitting on a stack of receipts you've been meaning to deal with? I was too. Here's how I fixed it once and for all.

I had an inbox full of them. Subscriptions, hotels, that one cab in Lisbon — all the SaaS I forgot I subscribed to. My accountant wanted them in a spreadsheet. My bookkeeping app wanted the PDFs. I didn't want to deal with any of it.

Now when a receipt lands in my Gmail, an AI agent spots it, looks at the PDF, pulls out the vendor, date, amount, and category, and writes a row to a Google Sheet. The original PDF gets filed away in a Drive folder. I never have to think about it again.

The receipts test

I gave it a five-page PDF with four real receipts and one deliberately scrappy one — a half-faded "Joe's Cafe £8.50" with no clear date.

Four went straight to a "Ready to post" tab — Office World, Figma, Bianca Bistro, Paddington Hotel — vendor, date, amount, all clean. The Joe's Cafe one landed in a "Needs review" tab with a note saying the date was unclear. That's the bit I care about: when the agent isn't sure, it doesn't make something up. It flags it.

Total time per receipt: somewhere between 15 and 30 seconds, mostly waiting for the model to think. Cost: a fraction of a cent.

How it actually works

Three pieces:

  1. A Gmail label. I made a label called Paper Trail/Inbox and a one-line filter that catches receipts from my usual senders. Anything in that label is fair game for the agent.
  2. A "gate" before the agent. Before the agent runs, a tiny check confirms the email actually has the right label. If not, nothing happens — no model call, no token spend. The check lives outside the agent itself — so you can change the rule without changing how the agent works.
  3. The agent itself. Once it's allowed in, the agent does the actual work: pull the PDF, look through the receipts, extract the fields, decide if it's confident enough to file directly or if it needs a human eye, write the row, archive the PDF.

The whole thing has access to exactly the eight Gmail/Drive/Sheets actions it needs to do its job — not the 200 you'd get by default. Less to confuse the model, less that can go wrong, easier to audit.

What I like about this setup

The agent's prompt only handles the fuzzy parts: looking at receipts, recognising vendors, judging whether something is worth flagging. The rest — does this email even belong here, what counts as a complete response — sits in policies you can read, switch off, or change without touching the agent.

Try it

The whole thing took less time to build than my last quarterly receipt-filing session. That's the actual story.

Here's the exact prompt I gave to the Workspace Assistant in ContextGate (that little robot icon on the bottom right) to build the whole agent for me. All I had to do was click approve to connect my Gmail, Drive, and Sheets.

Build a receipts-to-ledger agent. Trigger: Gmail watch on label Paper Trail/InboxAgent: reads each PDF attachment, looks at PDF receipts, extracts vendor / date (YYYY-MM-DD) / amount / currency / category (Office, Software, Travel, Meals, Other) / VAT / confidence (0–1). Output: if confidence ≥ 0.85, append to Sheet tab "Ready to post"; else append to "Needs review" with a notes column. Archive every PDF to Drive folder Paper Trail/Originals/<YYYY-MM>/. Update Gmail labels: remove inbox, add Processed (or Review). Policy: add a Gmail Label Gate that blocks runs where labelIds doesn't include Paper Trail/Inbox. Use claude-sonnet-4-6. Keep the toolbox to only the 8 tools needed.

Top comments (0)