Level 2: AI layer
AI layer
Eight short articles on getting AI tools to answer from governed definitions: meaning first, then grain and joins, metric contracts, a catalog, routing, tools, evals and token mechanics.
On this page
The seven guides in Level 1: Model the data showed how a model can let the wrong number through without an error. This one is about the next step: getting an AI tool to answer from definitions you own, and to say so when it can't.
Every part uses the same small example as the guides: one customer, one product, three revenue entries and two contract terms with term_start and term_end. Every SQL result shown was run on that example. Example data, not from a client.
The eight parts
Meaning before the model: build the ontology from evidence.
Most teams draw their business concepts from memory in a workshop. Start instead from what the systems already say, draft short cards, and have an owner sign each one.
Read part 1 →Grain, keys and allowed joins: rules a semantic layer can enforce.
Guide 1 showed a join that doubled April revenue without an error. Write the grain down, type every key, and the join stops being a warning in a document and becomes one the engine refuses.
Read part 2 →Metric contracts as code: one definition, many consumers.
Guide 5's contract says what a number means. This piece puts it where every consumer, a report, a subscription, an AI tool, gets the same value and the same answer status.
Read part 3 →The semantic catalog: what the AI should see instead of your schema.
Point an AI tool at the warehouse and it reads hundreds of cryptic columns. Point it at a catalog and it reads a few governed metrics, their dates, their dimensions and the rules.
Read part 4 →Route the question: governed metric first, curated query second, free-form SQL last.
“Semantic layer or text-to-SQL?” is the wrong argument. Use both, in a written order, and label every answer with the route it took.
Read part 5 →Tools and guardrails: make wrong requests impossible to express.
A rule written in a prompt can be ignored. A rule built into the tool can't be skipped. Give the model a tool that only accepts valid requests, and have it return a reason instead of a number when it says no.
Read part 6 →Evals and receipts: test the questions, keep proof of every answer.
Before people rely on AI answers, test the questions they'll ask against answers you worked out by hand. After, keep a receipt for every answer so anyone can check where a number came from.
Read part 7 →Where the tokens go: context, output, retries and caching.
Tokens aren't mostly the answer. They're the context you send on every call, the text the model writes back, and everything resent on a retry. Here's how each part works, with counts I measured on example data.
Read part 8 →The diagrams
Each part has one or two diagrams. You can also see them all on one page.
How to read it
In order, if you can. Parts 1 to 3 are about the model: meaning, grain and contracts. Parts 4 to 6 are about what a tool sees and can do. Parts 7 and 8 are about proving the answers and understanding the token mechanics.
Related
- All 8 parts of this seriesSeries overview
- All the diagrams in one placeDiagrams
- Level 1: Model the data (7 guides)Read level 1
- The 4-question checklistChecklist