anfra docsAlpha

Agentic analytics

What agentic analytics is, why connecting an agent straight to the warehouse fails, and the five layers that make it trustworthy.

What is agentic analytics?

Agentic analytics is an operating model in which people delegate analytical work to AI agents while retaining judgment and control. An agent can clarify a business question, plan an investigation, gather relevant context, query governed data, explain its findings, and identify uncertainty.

This is broader than chat with your data or text-to-SQL. Those approaches focus on generating a query from a prompt. Real analytical work also requires business definitions, context, review, evaluation, and a reasoning path that someone can inspect.

The model is rarely the problem. The system underneath the agent is. A chat box is easy to copy; the system underneath is the product.

Why agent → warehouse fails

With MCP, connecting an LLM to your data warehouse takes one sentence. Ask it "What was our revenue last month?" in four fresh chats and you can get four different numbers, each one confident and nicely formatted, and none of them the number Finance reports. The chats convert no currencies, keep voided invoices and test accounts, count tax as revenue, book annual plans in the month they're invoiced, or read from a deprecated table. None of them asks which revenue you mean.

Analytics is a stress test for agents: the action space is unbounded (raw SQL), the intent is ambiguous ("which revenue?"), and there's no built-in ground truth to check against. A direct connection fails in five ways:

#FailureWhat happensIn agent terms
F1Schema ≠ meaning"Revenue" can mean gross, net, recognized, invoiced, or collected cash. The agent picks one.It guesses intent from column names.
F2Unbounded actionsJoins and metric logic are rebuilt in every prompt, so answers drift.Raw SQL is too large a tool surface.
F3No verificationPlausible but wrong numbers, and a polished chart makes people trust them.Nothing tells the agent or the user that the answer is wrong.
F4No reviewed stateThe answer lives in one person's chat thread. Nothing is versioned, reviewed, or shared.There's no durable state humans can review.
F5No learningEvery fresh chat starts from zero and repeats the same mistakes.Failures don't improve the system.

This has happened before. Spreadsheets, self-service BI, and ad-hoc SQL each promised that anyone could do analytics, and each one produced competing versions of the truth until a constraint made it safe: a governed semantic layer. Agents need the same constraint, plus a few more.

The five layers

A trustworthy agentic analytics system has five layers. Each one does a different job and fixes one of the failures above.

The five layers of an agentic analytics system
  • question → agent
  • agent → l3 (reads)
  • l3 → agent (injects)
  • agent → l1 (calls)
  • l1 → agent (results)
  • l1 → warehouse (SQL)
  • agent → warehouse (raw SQL: skips every layer)
  • agent → l4 (trace)
  • l4 → l5 (failures)
  • l5 → l2 (opens a PR)
  • team → l2 (approves)
  • l2 → l3 (indexed)
  • l2 → l1 (deploys on merge)
LayerRoleFixesHow
L1 Semantic layerInterface: what the agent can doF2 Unbounded actionsTyped tools on governed metrics. Logic is defined once, not per prompt.
L2 Source of truthVersioned state: what is trueF4 No reviewed stateDefinitions live in Git. Every change is a pull request that a human reviews.
L3 ContextWorking memory: what the agent knows nowF1 Schema ≠ meaningNotes on metrics, tables, and incidents say what things mean here.
L4 EvalsVerification: scores every stepF3 No verificationEvery step is scored, so a wrong step is caught even without the right answer.
L5 Learning loopImprovement: turns failures into changesF5 No learningFailures and overrides become pull requests, so the next chat starts smarter.

The layers work at two different times:

  • At answer time, on every question, the agent calls the semantic layer (L1), reads the context attached to what it touches (L3), and is scored by evals (L4). It never sends raw SQL to the warehouse.
  • At change time, the learning loop (L5) proposes changes as pull requests to the source of truth (L2). The data team reviews and merges them, and the merged changes deploy to the semantic layer and context the agent uses.

L1 Semantic layer: the agent's tool interface

The semantic layer defines governed metrics, dimensions, and relationships and exposes them to the agent as tools. Instead of writing SQL against raw tables, the agent queries a metric by name:

query_metric("net_revenue", period="2026-09", compare="previous_month")

The semantic layer compiles the SQL; the agent never writes it. That gives the agent a smaller, typed action space with fewer ways to be wrong, and the same question returns the same number in every session.

The agent must go through the semantic layer and not bypass it with raw SQL when that's convenient. Otherwise it recreates the problem that self-service BI had to solve. The framework works with any semantic layer, such as dbt Semantic Layer, Cube, LookML, or anfra.

L2 Source of truth: versioned state

The source of truth is a Git repository that agents can read and humans can review. It holds the semantic-layer code, transformation code, a wiki of business definitions and decisions, and eval cases:

analytics/
├─ metrics/revenue.aml          semantic layer
├─ models/fct_revenue.sql       transformations
├─ wiki/
│  ├─ metrics/revenue.md        definitions
│  ├─ data/deprecations.md
│  └─ incidents/INC-2291.md
└─ evals/cases.yaml             eval cases

Agents need files they can read and diffs humans can review. A semantic layer that lives only in a GUI is hard for an agent to inspect or change.

The system is human-in-the-loop by default: the agent proposes changes as pull requests and never changes production logic silently. One reviewed file, with an owner and a history, replaces many unreviewed definitions scattered across chat threads.

L3 Context: working memory

A schema says what exists. Context says what it means here: which revenue is official, which table is deprecated, which incident affected last month's numbers.

SchemaContext
Three tables with revenue-like columnsUnqualified "revenue" means Net Revenue. Board reporting uses it.
rpt_revenue_monthlyDeprecated. Gross list price, no longer maintained. Don't use it.
September rows in credit_notesIncident INC-2291: an outage on 9 September led to SLA credits that reduce September revenue.

Context isn't a document dump into a vector store. Stale context confuses the agent, too much adds noise, and too little misses assumptions. Instead:

  • Attach context to things: metrics, tables, teams, time periods, and incidents.
  • Select what the question needs by following what the question touches.
  • Expire what's stale, such as an incident that has since been fixed.

The goal is organizational memory the agent can use, not just retrieval.

L4 Evals: verification at every step

Without evals, agentic analytics is a demo. With evals, it's engineering.

A final-answer eval needs ground truth, which analytics rarely has. Step evals don't: you don't need the right answer to catch a wrong step. Evaluate each step of the workflow:

StepWhat to check
InterviewDid the agent ask for clarification when the question was ambiguous?
PlanDid it choose the right metrics, dimensions, and segments, and state its assumptions?
ContextWas the context it used relevant and current?
ModelingAre new definitions correct, reusable, and consistent with conventions?
QueryDid it go through the semantic layer? Did it handle currencies, tax, voided records, test accounts, join fan-out, and revenue recognition?
PresentationDid it cite assumptions, avoid overclaiming, and keep correlation separate from causation?

An answer can pass most checks and still be far off, so score every step, not only the final number. Build the eval set from real questions and analyst corrections: each mistake someone actually made becomes an eval case. This is the analytics version of tests, CI, code review, and monitoring.

L5 Learning loop: the agent as a sensor

The agent is a sensor as well as a consumer. Its usage shows where the system's knowledge is missing:

SignalChange
The same question keeps coming upMake it a dashboard.
The agent keeps struggling with a metricClarify the definition.
Users keep correcting an explanationAdd what's missing to the wiki.
Analysts keep overriding the planAdd eval cases.

Each change goes to the source of truth as a pull request for a human to review. For example, if most unqualified "revenue" questions end up as Net Revenue, the agent can propose making Net Revenue the default for that term, and Finance approves or rejects the change. The system gets better with use, without retraining any model.

One question, end to end

Here is how a governed agent answers "What was our revenue last month?":

  1. Find the metric: search_metrics("revenue") returns the governed metrics, such as Net Revenue (owned by Finance), Bookings, and Cash Collected. (L1, L2)
  2. Find the context: search_context(...) finds the notes that say which revenue is official, which table is deprecated, and which incident affected the period. (L3, L2)
  3. Interview: "Revenue" means three different things here, so the agent states Finance's definition and asks which one you mean. (L4)
  4. Query: query_metric("net_revenue", ...). The semantic layer generates the SQL. (L1)
  5. Explain: explain_change breaks the change into new, churned, and existing customers and credit notes. (L1, L3)
  6. Present: the number and its trend, with assumptions, caveats, and links to the definitions it used. (L2)
  7. Evaluate: evals.run(trace) scores every step of the run. (L4)
  8. Learn: log_feedback() records the outcome and, when a pattern emerges, opens a pull request for the metric owner. (L5, L2)
  9. Ask again: a fresh session returns the same number. (L1)

The value isn't that the agent does every step on its own. Every step is explicit, inspectable, and evaluated.

Principles beyond analytics

The same blueprint applies to any domain where agents need to be trusted:

  1. Shrink the action space. Give the agent governed, typed tools instead of a raw interface such as SQL, a shell, or an API.
  2. Make state inspectable. Use files, diffs, and pull requests so humans can review what the agent changes.
  3. Engineer context; don't dump it. Attach knowledge to the things it describes.
  4. Evaluate each step, not just the final answer.
  5. Treat the agent as a sensor. Its failures show where your system's knowledge is missing.

In the self-service era, data teams modeled data so humans could explore. In the agentic era, they model data, context, and evals so humans and agents build trusted analytics together.

How anfra fits

anfra is in active development. It covers the first three layers today, though none of them is complete yet. The last two are planned.

Which layers anfra covers today
  • question → agent
  • agent → l3 (reads)
  • l3 → agent (injects)
  • agent → l1 (calls)
  • l1 → agent (results)
  • l1 → warehouse (SQL)
  • agent → warehouse (raw SQL: skips every layer)
  • agent → l4 (trace)
  • l4 → l5 (failures)
  • l5 → l2 (opens a PR)
  • team → l2 (approves)
  • l2 → l3 (indexed)
  • l2 → l1 (deploys on merge)
LayerStatus in anfra
L1 Semantic layerAvailable, still evolving. Every agent and application queries business data through the same governed language. See the building blocks below.
L2 Source of truthAvailable, still evolving. Definitions live in a code-native project: files that agents can read and humans can review.
L3 ContextAvailable, still evolving. The Semantic Catalog brings definitions, documentation, ownership, and lineage from your semantic layer, dbt, and LookML projects into one place agents can search.
L4 EvalsPlanned.
L5 Learning loopPlanned.

An anfra semantic project uses four core building blocks:

  • Data models map warehouse tables or SQL queries into dimensions and measures.
  • Datasets combine related data models into governed, queryable views.
  • Metrics define named, reusable calculations such as revenue or active users.
  • Dimensions define how metrics can be grouped and filtered, such as by date, plan, or country.

On this page