Stage 4 · AI data engineer · AI agent case
Agents on your data
Let an agent find the right table and read its numbers correctly, without ever seeing more than the person asking is allowed to see. I designed the semantic layer and the access path. It runs in production inside a financial platform.
One question, end to end
Definitions first, then a draft, then a person, then the query. The caller's identity is added by the gateway at the last step. Everything here is sample data.
- find_tablesThe semantic layer says what the table and its values mean.definitions
- draft_sqlThe model drafts SQL from those definitions.model
- confirmNothing runs until the person agrees.you
- run_querySubmit, poll, fetch a page. Cancel is available.as you
SELECT day, SUM(amount) FROM balances_daily WHERE status = 2 -- 2 = settled AND day >= DATE '2026-11-09' GROUP BY day
How it stays correct and inside its permissions
Definitions come first
- For the core tables: what each one means, what each value means, and which business questions it serves
- Dozens of core tables and a couple of hundred value meanings, written down once and read by the agent every time
Identity is injected
- The gateway attaches who is asking. The model cannot pass a user as an argument
- The query runs on that person's own account, so the permissions already in place apply
Long queries are four calls
- Submit, poll, fetch a page and cancel, so a slow query never blocks the conversation
- The user can stop it at any point
A person confirms
- Generated SQL is shown first and runs only after the user agrees
- The confirmation says whose permissions it will use
The decision: judge the result, not the SQL
Two correct queries rarely look alike, and one wrong value meaning looks almost identical to the right query. So evaluation compares what the SQL returns.
Scoring an agent's SQL sample
Case 1. Same meaning, different wording
Case 2. One wrong value meaning
What I took from it
- When an agent gets the number wrong, look at the definitions before the model.
- Authority belongs to the gateway. If the model can name the user, it can name someone else.
- A confirmation step costs one click and removes a whole class of silent mistakes.
Text-to-SQL fails on definitions, not on the model.
Next
Stage 3 · data platform
Reconciliation platform
Counts before amounts, and a day when about 40,000 rows became about 91.