← Back to everything else

Case study · ApproveHR assistant

How an assistant reads payroll
without leaking it

ApproveHR runs HR and payroll for Nigerian companies, so every answer the assistant gives could leak something. Honestly, the hardest part wasn't the code. It was picking the approach.

Role  built the assistant's current engine, backend and frontend Stack  TypeScript · Prisma · React · SSE Status  in production at Schulltech

What I built

  • A query catalogue built per request from the caller's permissions: fields gated, rows scoped, protected fields redacted, and the same rules enforced again on the server
  • An LLM adapter with server-sent-event streaming, a four-call cap per turn and cancel-on-disconnect
  • Per-organisation daily and monthly token budgets with an in-app gauge, and per-turn traces with four verbosity levels, backed by 47 tests

01

RAG? Let the AI write SQL? Neither

I tried RAG. I tried letting the AI write SQL and fetch the data itself. I experimented with all of them.

But ApproveHR isn't a messy database. The tables are fixed, the rules are fixed, and the permissions are already set. So the best thing was a catalogue: every module in the app, what can be asked about it, and who's allowed to ask. The AI just picks what it needs from there, and that worked just fine.

02

The catalogue is built from your permissions

Every field in the catalogue says what permission you need to see it, and which rows you're allowed to see. On every request, the AI gets one read-only query tool and a version of the catalogue built from the asking person's own permissions.

A field you can't see arrives redacted: the AI only learns that a value exists, never what it is. And the server checks the same rules again when the query runs, so even if the AI guessed the name of a hidden field, it gets nothing back.

So even if it wanted to spill your salary, it can't. It never had it.

question auth who is asking catalogue query schema fields gated by permission rows scoped to the caller model picks from what exists read streamed answer every turn: tokens metered, trace written at chosen verbosity

Permissions shape the tools before the model sees them. Filtering after the fact leaves a window where the data has already been read.

03

Read-only, on purpose

We don't want an AI making changes to people's data, especially payroll. So this engine only reads. If you want something changed, you change it yourself.

04

Streamed, with a ceiling

Answers stream in as they're written, so nobody's staring at a spinner. A turn can make at most four calls. And if you close the tab, the turn stops, instead of spending tokens on nobody.

05

What it costs, and what it saw

Token spend is counted per company, per day and per month, so a runaway conversation shows up before it becomes an invoice. Every turn writes a trace. But traces carry real pay figures, so how much they record is a setting: everything while I'm debugging, just timings normally, and off when it should be off.