# 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.

Source: https://getnao.io/blog/how-to-do-context-engineering-for-data-teams/
Published: 22 November 2026 by Claire Gouze

Over 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](https://thenewaiorder.substack.com/p/data-teams-should-become-context).

***

## What actually moves agent reliability

In my [first study](https://thenewaiorder.substack.com/p/first-context-engineering-study-are), 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.md` file 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](/blog/context-impact-analytics-agent/).

Then in my [second study](https://thenewaiorder.substack.com/p/how-i-improved-my-analytics-agent), 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:

1. Fix test errors (49→51%)
2. Add explicit date selection rules with DO/DON'T examples (51→60%)
3. 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%](/blog/improve-analytics-agent-reliability-steps/).

***

## 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](https://thenewaiorder.substack.com/p/how-to-make-semantic-layer-work-for-analytics-agents), I tried again, this time forcing the agent to use only the semantic layer. I got it to 82% by:

1. using the dbt semantic layer skill to generate it
2. using the dbt natural language querying skill so the agent can pick between the semantic layer and raw SQL
3. making the semantic layer exhaustive (every metric and dimension I needed in my tests)
4. reviewing entities and keys manually to avoid bad joins
5. enriching descriptions with business context
6. adding `rules.md` rules on date filtering, null handling, ambiguous terms
7. 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?](/blog/semantic-layer-impact-analytics-agent/).

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](https://docs.getnao.io/nao-agent/context-builder/rules-context) and [context builder databases docs](https://docs.getnao.io/nao-agent/context-builder/databases).

***

## 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](https://docs.getnao.io/nao-agent/context-engineering/evaluation).

**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](/blog/analytics-agent-benchmark-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](https://docs.getnao.io/nao-agent/context-engineering/playbook), and a broader view in [How to build a context stack for agentic analytics](/blog/how-to-build-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](https://docs.getnao.io/nao-agent/context-builder/databases)) |
| 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](https://docs.getnao.io/nao-agent/context-builder/rules-context)) |
| 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](/blog/how-to-do-data-modeling-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](https://docs.getnao.io/nao-agent/context-builder/semantic-layer), [how to make it work](/blog/how-to-make-semantic-layer-work-for-analytics-agents/)) |
| Company knowledge | Docs, glossaries, runbooks | a metrics glossary in Notion | Notion, Confluence and Obsidian synced to `docs/` ([business tools docs](https://docs.getnao.io/nao-agent/context-builder/business-tools)) |
| 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](/blog/launching-nao-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](/blog/launching-nao-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](https://x.com/_avichawla/status/2124453031559491672) 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](https://openai.com/index/inside-our-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](https://www.linkedin.com/posts/davidpmeyer_every-customer-i-talk-to-wants-this-once-activity-7529680828172390400-lVLC) into Microsoft Copilot Cowork as governed business context. Google made [Data Agent Kit](https://www.techceodaily.com/saas/google-data-agent-kit-ga-coding-agents) 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](https://medium.com/@andrei_15463/part-2b-hands-on-building-a-semantic-context-layer-with-knowledge-catalog-bigquery-property-ef18fcdacada) 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](https://www.accenture.com/en/insights/ai-data/ai-ready-data) (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](/blog/open-framework-context-engineering/).

***

## Where to start

If you're a data team starting today:

1. Write a minimal `rules.md` with your business definitions, ambiguous-term rules, and date logic.
2. Add schema and a small data sample to your agent's context.
3. Set up 20 unit tests based on real user questions.
4. Run an evaluation baseline.
5. Do failure analysis. Fix data model issues first, then rules.
6. 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](https://docs.getnao.io/nao-agent/quickstart), or watch the walkthrough in [Set up nao in 5 minutes](/blog/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.

## FAQ

**What is context engineering for analytics agents?**

It's the practice of selecting, structuring, and governing what information an analytics agent uses before generating an answer. In practice, it means a `rules.md` file, a curated schema, a data sample, and a test framework that measures what works.

**What improves analytics agent reliability the most?**

Clean data models and explicit business rules. In my studies, fixing the data model took the agent from 51% to 86% reliability. `rules.md` alone nearly matched full schema + profiling context.

**Is a semantic layer worth it for analytics agents?**

Not for small, clean data models. A good `rules.md` + schema + sample reaches the same 80%+ reliability at lower cost and latency. For large, multi-domain models with heavy joins, a semantic layer becomes worth the effort.

**How do I test and monitor my analytics agent?**

Build a unit test set of 20 to 50 real business questions paired with expected SQL. Run it after every context change. Track coverage, reliability, cost, speed. Categorize failures by root cause and fix them in order of impact. Once the agent is live, nao's [context recommendations](https://docs.getnao.io/nao-agent/context-engineering/recommendations) mine failed queries, downvotes and corrections to tell you which context file to fix.

**How does context engineering work with dbt?**

Your dbt project is the backbone of the context. nao syncs the repo so the agent reads your model docs, and if you define metrics with MetricFlow, the agent can query them through your `semantic_manifest.json` instead of writing the aggregation itself. Clean dbt models matter more than the semantic layer: in my studies, fixing the data model was the biggest jump.

**Where can I learn more about nao's approach?**

nao publishes open-source [context engineering skills](https://docs.getnao.io/nao-agent/context-engineering/skills) for Claude Code, Codex and Cursor that set up the context, write rules, create tests and audit it. See also the [nao context engineering principles](https://docs.getnao.io/nao-agent/context-engineering/principles), the [rules context docs](https://docs.getnao.io/nao-agent/context-builder/rules-context), and the [evaluation framework docs](https://docs.getnao.io/nao-agent/context-engineering/evaluation).
