rclabs · lab notebookentry Nº 004

FinSense: talking to your money, and the security feature that wasn't on

Objective
A photo of a receipt goes in, a transaction comes out, and you can ask it questions. How FinSense chains OCR, an LLM and tool calling, and the row-level-security gotcha I only found by reading my own code again.
Date
· 4 min read
Apparatus
aillmpostgresfastapishipped
Experiment
EXP-011 · FinSense
Observer
RC · Berlin

This is the story behind FinSense, built in one intense week in July 2025. There’s a two-minute demo on YouTube.

Every expense tracker I’ve tried dies the same way. Entering the data is boring, so I stop. My question was: what if a photo of a receipt were the whole input, and a plain question were the whole report?

“How much did I spend on groceries in March?” “What did I actually buy at the pharmacy last week?” No spreadsheets.

One week, two backends

FinSense started on Node and Express. Halfway through the week, on day six, I rewrote the entire backend in Python and FastAPI, because the AI and data work felt more natural there. The front end stayed React, TypeScript, Vite, Tailwind, Zustand and Recharts. (The README still describes the Node version. I’ll fix that.)

From photo to transaction, in three hops

1. OCR. The upload endpoint stores a processing record and starts a background task, so the request returns immediately. The task writes the image to a temp file and runs Tesseract through a tiny Node script using tesseract.js, with German plus English language data because my receipts come from Berlin. There’s no image preprocessing, so a crumpled receipt photographed at an angle gives messy text.

2. The LLM turns mess into structure. There are no regexes for “total” or “date”. Receipts are too varied for that. The raw OCR text goes to DeepSeek with JSON mode on and a prompt asking for a merchant, total, currency, date, category and a list of line items, each with a category. When the model returns broken JSON, a small repair step counts brackets and closes what’s open. If that fails, it retries with shorter input.

3. You confirm. This is the design decision I’m proudest of. The extracted data is not saved as a transaction straight away. The UI polls until processing finishes and shows you what it found, and you correct anything wrong before it’s saved. AI gets you most of the way, and a human signs off on the money.

Chat that can’t write SQL

The obvious way to “chat with your data” is to let the model write SQL. I didn’t want a language model composing queries against my bank history.

Instead the model gets twelve tools described as JSON schemas: get_transactions, get_receipt_items, add_transaction, create_budget and so on. The model only chooses which tool to call and with what arguments. Python runs a parameterized query scoped to your user ID, sends the results back, and the model writes the answer. It can decide what to look up. It can’t decide how to query the database.

Answers come back as typed envelopes (budget_breakdown, transaction_list, receipt_details, spending_analysis or plain text), and each type has its own React renderer. That’s why a budget question returns a chart instead of a paragraph.

The security feature that wasn’t on

I was proud of FinSense’s row-level security. Every table has a Postgres policy like this:

CREATE POLICY transactions_isolation_policy ON transactions
  FOR ALL USING (user_id = current_setting('app.current_user_id')::UUID);

and every request sets app.current_user_id before it queries. Even if the application forgets a WHERE user_id = …, the database itself refuses to leak someone else’s rows. That was the idea, anyway.

Reading the code again for this post, I found the catch. Postgres doesn’t apply RLS policies to the table’s owner. The app connects as the same role that created the tables, and I never ran:

ALTER TABLE transactions FORCE ROW LEVEL SECURITY;

So as deployed, the policies almost certainly do nothing, and the real protection is the user_id filter in every query, which is exactly what RLS was meant to back up. A few background status updates don’t even set the user context.

I’m not embarrassed by this. I’m fascinated by it. It’s the perfect example of a safety feature that looks enabled: the policy exists, the context is set, and everything works. You’d only find out it wasn’t protecting anything on the day you needed it. The fix is two lines: FORCE ROW LEVEL SECURITY, and connect as a non-owner role.

The rest of the honest list

  • Redis is connected and never used. There’s a cache helper and zero callers. Sessions are stateless JWTs.
  • Budget alerts go to a log file. The email and push delivery paths are TODOs.
  • “Multi-currency” means labels, not math. Each record stores its currency, but nothing converts, so totals across currencies don’t add up.
  • No tests. They were deleted during the cleanup and never came back.
  • Two file paths still point at a folder on my own laptop.

What I learned

  • OCR is the easy 80%. The hard 20% is turning messy text into numbers you’d trust, and then letting a human confirm them.
  • Tool calling beats text-to-SQL for anything involving money. Keep the model on the what and your code on the how.
  • Test your security, don’t just enable it. One integration test that logs in as user A and tries to read user B’s rows would have caught the RLS gap on day one.

The code is at github.com/chandrasekar-r/FINSENSE.

Recorded byRCBerlin · 25 Sept 2026
Witnessed byyou, just nowquestions or corrections: rcsekar.v3@gmail.com