<!-- Generated from typed source content. Do not edit this file. -->
# Trusted AI Answers For Leadership

> How a governed data layer taught Cortex the grain, joins, and metrics — and stopped a fluent guessing machine from reaching the humans who needed it.

- Author: Paul Yu
- Role: Senior Analytics Engineer
- Employer: Viral Nation
- Year: 2026
- Theme: AI Readiness
- Human article: [https://paul-yu.com/case-studies/semantic-layer-for-ai](https://paul-yu.com/case-studies/semantic-layer-for-ai)
- Structured data: [https://paul-yu.com/agent/case-studies/semantic-layer-for-ai.json](https://paul-yu.com/agent/case-studies/semantic-layer-for-ai.json)

## Evidence

| Value | Measure | Evidence level |
| --- | --- | --- |
| 9 | grain-defined data objects | Repository backed |
| 16.0M | post-observation rows modeled | Measured |
| 114 | field-role corrections | Measured |
| 32 | questions tested live | Measured |

## Situation

Almost no one could use the Cortex agent. It wrote valid SQL and still guessed wrong — mixed row types, unsafe joins, mislabeled fields, and business rules that only lived in analysts’ heads.

## Task

Teach the AI how to use the data so natural-language answers were safe enough for humans who could not inspect the warehouse — especially leadership.

## Action

I rebuilt the reporting foundation: clear grain, explicit relationships, cleaned fields, governed metrics, narrow tool routing, and analyst-written SQL examples. I reviewed 319 exported fields, fixed 114 roles, defined 24 metrics, and tested 32 known questions against live data.

## Result

The agent stopped behaving like a guessing machine. Leadership started using it with confidence. AI still wrote the SQL; the data contract made the answers trustworthy.

## System flow

Source data → Grain-safe reporting model → Semantic rules + metrics → Tested AI answer

## Technical notes

### Grain-first dimensional model

Every data object states what one row means. Dimensions describe the business entities. Facts store observations and comments. The mart has one campaign-post reporting row.

### Campaign-post bridge

A post can belong to several campaigns. The bridge records each membership once so campaign joins do not quietly copy post measures.

### Metric contract

Each metric has a formula, row grain, filters, and a list of valid dimensions. Engagement rate keeps the same meaning from one question to the next.

### Test question set

The set pairs common questions with SQL that has already been checked. It catches changes that make an old answer fail and shows where the AI still needs help.

## Ownership

I built and documented the row grain, identity rules, relationships, metrics, tool routing, and custom instructions. I also reviewed the semantic fields, wrote the verified queries, and ran the live checks.

## Limitations

The 32 questions cover known use cases. They cannot prove that every new question will get a correct answer. The 16.0 million rows measure scale, not accuracy. Leadership use is an operating observation, not a controlled accuracy test.

## Takeaway

Nobody could use the agent until the data taught it the business. Clear row meaning, safe joins, governed metrics, and verified examples came first. Then leadership could trust the answers.

## Tools

Snowflake Cortex, Semantic YAML, SQL, Dimensional modeling, Verified queries, Agent observability
