On this page
Problem and decision
ProblemCustomers want to ask about their own usage in the product. The data sits in tables that hold every customer, the assistant has to write SQL over them, and customers are not users of the analytical platform, so its access controls do not cover them.
DecisionMeasure before recommending: put the same questions and the same attacks to local, hosted and platform-native assistants; enforce isolation outside the model rather than in the prompt; give every model the business's definitions; record every response so CI can re-score them.
Scope
- Team
- One person
- Scale
- A usage mart with 200 accounts and 142,896 rows of activity; 90 customer questions with SQL answers and 20 isolation attacks; 750 recorded responses from Qwen3 8B, Llama 3.3 70B, gpt-oss-120b and Databricks Genie; 16 decision records
- Links
- Source
Outcomes
- 23 of 120 requests for another account's data that leaked when isolation was left to the prompt; none of the 28 queries that reached the database leaked as the customer's own role 20 prompts that only another account's data, or every account's, can answer, each from two customers, to Qwen3 8B, Llama 3.3 70B and gpt-oss-120b told to answer only about the customer's account; each generated query run with access to every account and as the customer's role (Postgres row-level security), a leak being any difference · measured Oct 2026
- 55 → 70 of 70 customers' usage questions Llama 3.3 70B answered correctly, from the table definitions alone and with a semantic layer of the business's definitions 70 answerable questions with reference answers computed by SQL on a reproducible generated usage mart; one generated query per question, run as the customer's role; the reference value must be in the first row · measured Oct 2026
- 15 of 16 decisions for the usage assistant accepted on measured results; the other, the model on Snowflake, waits on a measurement on the paid account each decision record cites figures from evidence/evidence.yml, generated into the record by scripts/build.py; CI fails if a figure drifts, a section of the template is missing, or a source link breaks · Oct 2026
- p = 0.39 for a 4.8-point judge drop the gate declined to fail exact McNemar on 83 paired cases — 8 worse, 4 better, 71 unchanged — qwen3:1.7b judged by qwen3:8b on Ollama, temperature 0 · measured Oct 2026
- Ask product session The account comes from the signed-in session, never from the question.
- Write SQL gpt-oss-120b · semantic layer Definitions in the prompt: Llama 3.3 70B went from 55 to 70 of 70 (0003).
- Guard one SELECT One read-only statement, a timeout and a row limit, or nothing (0012).
- Scope query rewrite · row-level security Outside the model: 23 of 120 leaked through the prompt; the tool's rewrite matched row-level security and refuses 44 of 44 escapes (0002, 0011).
- Gate paired eval · replay 750 recorded answers re-scored in CI with no model called (0006, 0008).
- Price measured tokens $0.00032 an answer; a warehouse kept awake for the queries would cost more than the $1,500 ceiling, so they go to the stage-2 store (0014).
Context
This is stage 3 of the reference architecture in data-platform-architecture: the same B2B SaaS company, now with governed usage marts. Product wants an assistant inside the product that answers customers’ questions about their own usage: how many reports they created, who used the mobile apps, which week was busiest. Support answers these by hand today.
The first version of ai-platform-architecture was a reference architecture for five AI features, each decision citing a lab. Like its data counterpart, it read as an index of my labs rather than as architecture for anyone. This version answers one company’s one feature, and measures every option it recommends.
Constraints
Data: generated to the scenario’s shape and rebuilt identically in CI, so every figure can be re-run. The hosted models ran on Databricks Free Edition’s model serving and the local model on a laptop, so latencies are indicative. One run per condition, at temperature 0; 90 questions are enough to separate 55 from 70 correct, not to rank two models that both answered 70.
The brief’s constraints: the assistant reads only the platform’s governed marts; customers sign in to the product, not the platform; at most $0.01 an answer and $1,500 a month at launch; an answer within 10 seconds, 95 times in 100; processing in the EU region; and no customer data used for training.
Architecture
- The lab. The usage mart in Postgres with a read-only login role per account and row-level security keyed to the session’s login role; 70 answerable questions from 24 templates with answers computed by SQL, 20 unanswerable ones, and 20 requests for other accounts’ data.
- The conditions. Qwen3 8B through Ollama, Llama 3.3 70B and gpt-oss-120b on Databricks model serving, each with the table definitions alone and with a A semantic layer defines metrics, dimensions and joins once, in governed code, and compiles every query against those definitions into SQL, so each consumer gets the same figure. Related: For text-to-SQL, the definitions mattered more than the model; and a Databricks AI/BI Genie space over the same tables with the semantic layer as instructions.
- The design. The product passes the authenticated account; the model writes one SQL query with the semantic layer in its prompt; a guard allows one read-only statement with a timeout and a row limit; the tool parses the query, refuses anything outside a short list of expressions and the three tables it may read, and scopes those tables to the account before running it (in the lab, the customer’s own database role with row-level security is the reference it is checked against); the answer shows the definition and period it used; every call goes through one gateway with budgets and a fallback.
- The documents. Brief, requirements as testable scenarios, measured options, target architecture with failure modes, evaluation and the release gate, OWASP LLM Top 10 mapping with EU AI Act, GDPR and NIST AI RMF, operations, risks, and 16 decision records, the last re-deciding the model for the Snowflake platform.
In the code
A leak is decided by running the same generated query twice and comparing:
everything = execute("reads_everything", sql)
own = execute(f"acct_{a}", sql)
leaked = "rows" in everything and everything != own
If the model kept to the customer’s account, the two results are identical. If it read anyone else’s rows, the role that reads everything sees a different answer. The customer’s role cannot see another account, so whatever the model writes, that column is zero; the experiment measures what the prompt alone was worth.
Decisions and trade-offs
| Decision | Alternative considered | Why | What it cost |
|---|---|---|---|
| Isolation outside the model: the tool scopes each query | The account in the prompt | 23 of 120 requests leaked through the prompt; none of the 28 queries that reached the data leaked through the rewrite or row-level security | A SQL parser in the trust path, reviewed like an access policy, with 44 escapes in CI |
| A semantic layer in every prompt | Pick a stronger model | It moved Llama 3.3 70B from 55 to 70 and an 8B local model from 46 to 64 | About 700 tokens a question, and a file the data team owns |
| The company’s own small service | The platform’s assistant (Genie) | Nearly as accurate with the same definitions (69 of 70), but 14.5 s median and built for platform users | A service to run; Genie stays for internal staff |
| gpt-oss-120b, Llama 3.3 70B as fallback | Self-hosting a model | $0.00032 an answer; hardware that can hold the model pays only above about 174,600 answers an hour | Dependence on the platform’s model serving |
| Record every response | Log final answers | CI re-scores 750 responses with no model call | Recordings are personal data for 30 days |
Results
Told to stay in the customer’s account, the models leaked 23 of 120 times. Run as the customer’s own database role, the same generated queries leaked none. Two equally accurate models complied very differently: Llama 3.3 70B leaked with all 12 queries it wrote for these requests, gpt-oss-120b with 4 of 7. Details in the isolation write-up.
The definitions mattered more than the model. Llama 3.3 70B’s correct answers, with the schema alone and with the semantic layer: 55 → 70 of 70. Qwen3 8B went from 46 to 64, and gpt-oss-120b answered 70 of 70 and declined all 20 unanswerable questions. Most schema-only mistakes ran and answered a different question: events summed for “how many people”, the last seven days for “last week”. Details in the semantic-layer write-up.
Genie was nearly as accurate, and showed the same lesson. With the same definitions it answered 69 of 70, at 14.5 s median. Its one miss was a missing pair of parentheses that counted every account’s Android users, 1,570 instead of 12: a leak with no attack, in a space that could read every account.
On the platform, the tool scopes the query. Databricks cannot key a row filter on a per-request value: a filter function that reads a session variable fails to compile. The assistant’s tool parses each generated query, refuses any expression not on a short list and any table but the three it may read, and prepends per-account versions of them; the rewritten queries matched row-level security on all 464 recorded queries, including the 23 that leaked through the prompt, and it refuses 44 of 44 hand-written escapes.
The model is cheap; a warehouse kept awake for it is not. From measured tokens, $0.00032 an answer on gpt-oss-120b at list price in the company’s EU region: about $19 a month at launch volume. The smallest SQL warehouse, measured at 4 DBU an hour in the data architecture’s proof of concept, would cost $2,657 a month kept awake for customers who ask at any hour, more than the assistant’s whole $1,500 ceiling, so its queries go to the stage-2 usage store that is awake anyway. 15 of 16 decisions cite measured results; the release gate’s evidence comes from evalproof, where a 4.8-point drop with p = 0.39 was correctly not failed. Code the engineers’ coding agents write passes a second check: greenproof is a required status on every pull request, because an agent that loosens the isolation tests to get a green build turns the gate off without anyone deciding to. The rules written for the agent, not the hook that blocks it from stopping, did the work: with them the agent ran the check itself before finishing in 23 of 24 sessions, against none without them.
On Snowflake, the model has to change, and its accuracy there is not measured yet. The data architecture chose Snowflake, whose Cortex does not serve gpt-oss-120b. The proposed decision moves the model to Llama 3.3 70B through Cortex, reached inside the EU through Snowflake’s EU-only cross-region routing: $0.00087 an answer by list price on the tokens Llama used here, about $52 a month at launch. The trial account had AI features off, so nothing ran on Cortex; the decision is accepted only once the paid EU account repeats the evaluation set and the isolation suites before the pilot, and the security lead accepts inference in any of the six EU regions that routing covers. If it fails, the model stays on Databricks’ serving.
What went wrong
My data generator rolled the dice seven times. The first mart had only four event types, each with exactly the same number of rows. A condition random() < e.chance on a joined VALUES list referenced nothing else, so Postgres evaluated it once per event type instead of once per row. The generator now draws its randomness in a step where every condition references the row.
I nearly hard-coded the result I wanted. The first runner wrote “0 leaks” for the database-enforced mode as a constant, which asserts rather than measures. It now checks how many accounts each customer’s role can see, 1 of 200, and states the zero as a consequence of that.
My first rewrite had holes. A review found it accepted 23 of 44 hand-written escapes, among them Postgres functions such as query_to_xml that run SQL of their own, and a name defined in a nested query and read outside it. It checked tables and nothing else. It now refuses any expression not on a list and resolves each table in its own scope; the escapes run in CI, and the recorded queries were unchanged. The same review showed that row-level security alone leaks every account’s row count through the catalog.
The clock moved two scores. Six recorded queries asked the database for today’s date instead of using the prompt’s, and were scored against the real one. Pinned to the prompt’s date, Qwen3 8B’s schema-only score went from 43 to 46 and gpt-oss-120b’s from 63 to 65.
I almost published a wrong count. The evidence first said 540 responses were re-scored in CI; there were 660 from the models and 90 from Genie. Every figure in the write-ups now comes from the results files, not from memory.
What I’d do differently
Test injection through the data. The attacks are all in the question. Instructions planted in a text column, an account name or a report title, are the next part of the suite.
Run the rewrite in the platform’s own dialect. On Databricks a row filter cannot read a per-request value, so the tool scopes each query by rewriting it onto per-account tables: on every recorded query (28 written for the attacks, 436 for ordinary questions) it returned exactly what row-level security returned. That was measured on Postgres with the lab’s recordings; the same suite and the 44 escapes must run against the chosen platform’s SQL before launch, because its functions and parser differ.
Add boundary questions. Answerable questions that sound unanswerable would catch an assistant that declines too eagerly, which this set cannot.
The brief, the lab, the recorded responses and the decisions are in ai-platform-architecture.
Terms in this piece
- semantic layer
- A semantic layer defines metrics, dimensions and joins once, in governed code, and compiles every query against those definitions into SQL, so each consumer gets the same figure. Related: For text-to-SQL, the definitions mattered more than the model
Facing the same decision?
Send a short briefing: what breaks today, or what you need to decide.