How to do context engineering for analytics agents
What context engineering is for data teams, and what 3 studies on analytics agents show: what moves reliability, if a semantic layer pays off, how to test.

22 November 2026
By Claire GouzeFounder @ naoOver the past few months, I ran three studies on context engineering for analytics agents. Same data model. Same 40 unit tests. Different context setups each time.
Context engineering for data teams is the work of choosing, structuring and testing everything an analytics agent reads before it writes SQL: schemas, sample rows, business rules, metric definitions, docs. It's data engineering applied to the agent's context: one source of truth per definition, versioned like code, and a test suite that tells you whether each change made the agent better or worse.
The goal was simple: figure out what actually makes an analytics agent reliable, instead of repeating claims about semantic layers, RAG, or ontologies without evidence.
Here is what I found, and how you can apply it to your own data team.
If you want the broader framing on why data teams should own this, start with Data Teams Should Become Context Teams.
What actually moves agent reliability
In my first study, I tested 30 different context setups against the same 40 text-to-SQL tests. The best setup reached 45% reliability. Nothing exotic. Just three pieces of context:
- data schema
- a sample of rows per table
- a
rules.mdfile with business logic and edge cases
Things that sound fancy but did not help:
- a full dbt repo pumped into context (noisy, dropped performance)
- a MetricFlow YAML as a shortcut (no improvement vs
rules.md) - a metrics-store-style semantic layer (killed coverage)
The rules.md file was the single biggest lever. Well-structured rules alone nearly matched full schema + profiling combinations. More detail on which context piece matters in Which context really improves analytics agent performance.
Then in my second study, I pushed that 45% baseline to 86% by doing failure analysis on the 28 tests that were failing. The breakdown:
- 18 data model errors
- 6 date selection errors
- 4 test errors
Fixing them in that order looked like this:
- Fix test errors (49→51%)
- Add explicit date selection rules with DO/DON'T examples (51→60%)
- Clean the data model: add missing computed fields, document metric sources of truth, clarify ambiguous terms like "our users" (65→86%)
The takeaway: context engineering is mostly data engineering. Most agent failures are data model failures in disguise. Step-by-step in How I improved my analytics agent reliability from 45% to 86%.
Should you add a semantic layer?
Short answer: not in your first pass. Maybe later, and only at scale.
In study #1, adding a dbt MetricFlow semantic layer reduced hallucinations but also reduced answers to almost zero. It was 4x more costly in tool calls and 3x slower, and the semantic YAML added no performance vs a plain rules.md.
In my third study, I tried again, this time forcing the agent to use only the semantic layer. I got it to 82% by:
- using the dbt semantic layer skill to generate it
- using the dbt natural language querying skill so the agent can pick between the semantic layer and raw SQL
- making the semantic layer exhaustive (every metric and dimension I needed in my tests)
- reviewing entities and keys manually to avoid bad joins
- enriching descriptions with business context
- adding
rules.mdrules on date filtering, null handling, ambiguous terms - adding a nao context layer so the agent doesn't rely solely on dbt MCP for discovery
More detail in Does a semantic layer improve analytics agent performance?.
My honest verdict after running it:
- the semantic layer reduces hallucinations, it doesn't remove them. The agent still has to pick the right metric among many.
- at 12 tables with clean OBT models, I hit 86% without a semantic layer and 82% with one. It's a tie.
- semantic-layer agents are more expensive and slower because of MCP tool calls.
- there is probably a complexity threshold (hundreds of tables, heavy joins) where a semantic layer starts paying off.
If you're a solo data analyst or a small team, skip it. Invest in rules.md and a clean data model first. If you run 150+ tables across multiple domains with real governance pain, it's worth the effort.
Reference patterns are in the nao rules context docs and context builder databases docs.
How to set up a testing and monitoring framework
You cannot improve what you cannot measure. This is the part most teams skip, and it's the one that compounds.
Here is the setup I use for every context change:
1. Define your success metrics. I track 5:
- coverage: % of questions the agent attempts to answer
- reliability: % of correct answers
- cost: tokens spent per answer
- speed: time to first useful response
- data scanned: volume queried against the warehouse
2. Build a unit test set. 20 to 50 real questions from your business users, each paired with the expected SQL. Store them as YAML. Cover KPI lookups, cohorts, error analysis, distributions. Mix single-table and multi-join queries. See the nao evaluation framework docs.
3. Run evaluation after every context change. Treat rules.md edits and data model changes like model releases. Re-run the tests. Diff the results. Keep what improves reliability, revert what degrades it. The full setup is in How to benchmark your analytics agent with a context stack.
4. Categorize failures, don't fix randomly. Every time a test fails, tag the root cause: data model, date scope, business ambiguity, test error, out-of-scope. This is how I found that 18 of 28 failures in my first study were data model issues, which told me exactly where to invest.
5. Monitor in production. Log user questions, agent answers, and flag runs for human review. Feed confirmed failures back into your test set. This is the loop that turns a demo into a system.
The playbook is in the nao context engineering playbook docs, and a broader view in How to build a context stack for agentic analytics.
The context layers of an analytics agent
Here is everything above in one table: what goes into the agent's context, and where it lives in a nao project.
| Layer | What it is | Example | How nao handles it |
|---|---|---|---|
| Schema | Tables, columns, types, descriptions | orders.amount is net of refunds | nao sync writes a columns.md per table from your warehouse (databases docs) |
| Data sample | A few real rows, plus column stats if needed | the actual values of orders.status | preview.md per table by default, profiling.md as an option |
| Business rules | Definitions, ambiguous terms, date logic | what "our users" means, how to filter "last month" | RULES.md, loaded with every message (rules docs) |
| Data model | Clean models, computed fields, one source of truth per metric | a single revenue column instead of three | your dbt repo, synced under repos/ (see 8 data modeling rules for AI agents) |
| Semantic layer (optional) | Governed metrics and dimensions | revenue as defined in dbt MetricFlow | the agent queries your MetricFlow manifest with execute_semantic_query (semantic layer docs, how to make it work) |
| Company knowledge | Docs, glossaries, runbooks | a metrics glossary in Notion | Notion, Confluence and Obsidian synced to docs/ (business tools docs) |
| Tests (offline evals) | Real questions paired with the expected SQL | "What is the total revenue from all orders?" | nao test runs the YAML files in tests/ |
| Production feedback (online evals) | Failed queries, downvotes, corrections | an answer users had to regenerate | context recommendations rank fixes and point at the file to change |
You don't have to write all of this by hand. The open-source nao context engineering skills run each step from Claude Code, Codex or Cursor: set up the context, write RULES.md, create tests, audit, add a semantic layer, deploy.
What changed in November 2026
Eight months after I first published this guide, here is what the data community is debating about context engineering.
- The term is settling. Avi Chawla's breakdown of prompt, context, harness and loop engineering defines context engineering as everything the model sees on a turn, not just the prompt. The window is finite, so the work is to rank inputs and cut everything that isn't pulling weight. Same lesson as study #1: pumping the full dbt repo into context made the agent worse.
- The reference design is a data team's. Ask ChatGPT what context engineering for analytics agents is and it points to OpenAI's post on its in-house data agent. That agent is grounded in six layers of context: table usage, human annotations, code-level enrichment of how tables are built, institutional knowledge from Slack, Google Docs and Notion, memory of past corrections, and live warehouse queries. It's evaluated with questions paired with golden SQL, comparing the resulting data, run like unit tests. Its lessons: fewer, consolidated tools work better, and table meaning lives in pipeline code, not just in schemas. Another reason to fix the data model first.
- Vendors are shipping business context layers. Databricks now brings Genie Ontology into Microsoft Copilot Cowork as governed business context. Google made Data Agent Kit generally available: MCP tools and skills that let coding agents like Claude Code and Codex work on BigQuery, dbt and Dataplex Knowledge Catalog. Andrei Fateev's hands-on guide builds that context layer on Knowledge Catalog, starting from the observation that stuffing schemas, join rules and metric definitions into a static system prompt fails in production.
- Context is now the bottleneck, not the model. Accenture's AI-ready data report (2,000 large organizations surveyed) finds only 7% leading on AI-ready data, and over 80% of executives delaying, limiting or altering AI initiatives because of data. Their example: a price of "10" is useless to an agent until it knows whether it's a unit price or a list price.
This is the direction the studies pointed to: most failures are business context and data model failures. The open question is where that context lives. My position hasn't changed: it should be files your team can read, review and diff, not locked inside one vendor's platform. That's the case for an open framework for context engineering.
Where to start
If you're a data team starting today:
- Write a minimal
rules.mdwith your business definitions, ambiguous-term rules, and date logic. - Add schema and a small data sample to your agent's context.
- Set up 20 unit tests based on real user questions.
- Run an evaluation baseline.
- Do failure analysis. Fix data model issues first, then rules.
- Skip the semantic layer unless you have a large, messy model.
You can get a nao project running in 5 minutes with the nao agent quickstart, or watch the walkthrough in Set up nao in 5 minutes.
Final takeaway
Context engineering is not a tooling question. It's a discipline: clean data models, explicit rules, versioned context, and a test loop you run every time something changes.
If dashboards needed a governed data layer, analytics agents need a governed context layer. Teams that treat context like infrastructure will ship reliable agents. Teams that hope a semantic layer will fix it won't.

Claire
For nao team
Frequently Asked Questions
Related articles
product updates
Launching nao agentic BI builder
Sign up on nao Cloud, connect your warehouse, add business context, and deploy your own agentic BI to the whole company from the nao UI. No CLI needed. Still open source.
Buyer's Guide
How to Choose Your First BI Tool: Top 3 Free Options
The 3 free BI tools companies adopt when they start their analytics journey, compared on features, pricing, setup and how far they scale.
Buyer's Guide
Looker Conversational Analytics, Data Agents and Data Apps
Looker Conversational Analytics, data agents and Data Apps reviewed: how Gemini in Looker works, its limits, and nao as the open source alternative.