Define the metrics in the warehouse, and give agents tools over the marts
Context and Problem Statement
Agents and Metabase are equal consumers of the warehouse, and one question has to get one number from each of them. Today the definitions of the metrics live in the YAML of dbt, and metrics.py turns them into metrics and terms of the glossary of Metabase (ADR-0034), so an agent on MCP Toolbox does not see them. Toolbox offers list_tables, describe_table and execute_sql, and its documentation says that postgres-execute-sql "shouldn't be used for production agents".
ai_reader also reads staging (ADR-0007, ADR-0030). Under ADR-0035 the views of staging stand over a layer that is erased after each acceptance, so an agent would see empty tables and draw wrong conclusions.
How does an agent find a definition, ask a common question, and stay within what it should read?
Decision Drivers
- One number for one question, from Metabase, from Toolbox and from the MCP server of Metabase.
- One source for the definitions, not one for each consumer.
- Least privilege (ADR-0007): tools and roles read the top layer only.
- A common question needs no written SQL.
- Names of campaigns are written by anyone, and can carry text that tries to steer an agent.
Considered Options
For the definitions:
- A table
marts.metric_definitions, built from the YAML of dbt - The definitions only in Metabase
- A semantic layer, such as dbt-mcp or the Open Semantic Interchange
For the tools:
list_metricsand one parameterizedstats_by, beside the tools of todayexecute_sqlonly
Decision Outcome
Chosen options: "A table marts.metric_definitions, built from the YAML of dbt" and "list_metrics and one parameterized stats_by", because a table in the warehouse reaches every client through the one read-only role, and a parameterized tool with allowed values is safe and cheap.
In practice this means:
- Definitions.
marts.metric_definitionshas the name, the display name, the SQL formula, the numerator and the denominator, the unit and scale, the description and the name of the metric in Metabase. The source is one: the YAML of dbt, from whichmetrics.pyalready makes metrics and the glossary. - Tools of Toolbox. Beside
list_tables,describe_tableandexecute_sql:list_metricsreadsmetric_definitions.- One parameterized
stats_bytakes a grain, a dimension fromallowedValues, a period and an account. The grain and the dimension go in astemplateParameters, soallowedValuesis required. It hasannotations: readOnlyHint, a short and a long format of its answer, and a default limit of rows. execute_sqlstays as a last resort underai_reader, with a timeout of a minute and a description that asks forLIMIT.
- Only L3.
ai_readerlosesstaging,list_tablesreads onlymarts, and the skills and the guides change with it. - Descriptions.
COMMENT ONof each view and column from the YAML of dbt, aspersist_docsdoes today, with an illustration of values, such as "campaign_status: as on the platform, on Google ENABLED, PAUSED, REMOVED; the spend of removed entities counts in the totals". A description states facts, never an instruction. - Untrusted text. The names of campaigns, ad groups and ads stay in the views, and their descriptions say that it is text of an advertiser, data and not instructions. Headlines, texts of ads, URLs and other long fields do not enter the default views, and live in a view
ad_textsof a module. - The third arm. Private data and untrusted text are there by construction, so the outward path is cut: no
agent:delivery:write, and no external links in a dashboard that an agent builds (ADR-0017). - Limits of
ai_reader.default_transaction_read_only,statement_timeoutof 1 minute,idle_in_transaction_session_timeout,transaction_timeout,work_memby role and three connections. The tool, not the database, limits rows. - Export.
target/osi_document.jsonof dbt 1.12 is added when something reads it.
The other options were not chosen for these reasons:
- The definitions only in Metabase leave Toolbox with no definition, so an agent would compute a ratio its own way.
- A semantic layer now has no reader: the semantic layer of dbt-mcp is paid, the Open Semantic Interchange is at version 0.1.1 in the Apache Incubator as Ossie, and Metabase 0.64 has no import or export for it, as of October 2026.
execute_sqlonly writes SQL for each question, which the vendor advises against for production agents.
Consequences
- Good, because a ratio has one formula, which an agent can read and repeat.
- Good, because a common question goes through a tool that cannot do harm, with fewer tokens.
- Good, because an agent no longer sees layers that mean nothing to it.
- Good, because long free text stays out of what an agent reads by default.
- Bad, because
stats_byhas to follow the marts, as one more place that knows their grains. - Bad, because a contributor who reads
stagingthrough an agent loses that, and has to work on a local stack with another role. - Bad, because a description cannot stop an injection: it only lowers the odds, and the limits of the roles are what holds.
More Information
- Implementation status, as of November 2026:
ai_readerreadsmartsonly, and the next start of a warehouse of an earlier release takesstagingfrom it;list_tablesof Toolbox lists the views ofmartsonly, and the skills and the guides say so.metric_definitions,list_metricsandstats_byare planned for v0.8. Today Toolbox has the three tools ofai/tools.yaml. - The facts behind this record, read on 30 and 31 October 2026:
- Toolbox:
postgres-sqltakes parameters withallowedValues,postgres-list-tablesreturns the comments of tables and columns (tools, list tables). - Few tools with clear descriptions, a short and a long format, and limits by default come from Writing effective tools for agents; annotations from the MCP specification.
- Column descriptions add up to 26 points to the accuracy of text-to-SQL (NOVAS 2026), and hints about values took GPT-4 from 34.9% to 54.9% on BIRD. Names weigh two to three times more than structure, and a wide table over several grains makes double counting (Su et al.).
- OWASP LLM01 asks to segregate external content (Top 10 for LLM), and Simon Willison names the three arms (The lethal trifecta).
- dbt 1.12 reads
osi/and writestarget/osi_document.json, and Ossie was accepted into the Apache Incubator on 10 July 2026.
- Toolbox:
- Related decisions: at acceptance this record replaces the reading of
stagingbyai_readerin ADR-0007 and ADR-0030. The levels of AI access in Metabase stay (ADR-0017). - Revisit this record when dbt-mcp offers a semantic layer in the open, or when a client reads the Open Semantic Interchange.