Defining metrics and rules
You make an analytics agent correct by writing down what your data means. A connected warehouse tells the agent what tables exist. Metrics and rules tell it how to use them. This is the part that turns a query that runs into an answer you can trust.
The agent does not know your business until you write it down. Define your metrics, encode your rules, and add documentation, all in the context the agent reads on every question.
Defining metrics
A metric is a name plus the exact logic behind it. You define it once so every answer uses the same version.
- Revenue is paid orders minus refunds, excluding internal accounts.
- Active user is an account with a session in the last 28 days.
- Pipeline is open deals weighted by stage, excluding closed-lost.
With these written down, the agent stops guessing whether refunds count. It reads the definition and builds its query from your logic.
Encoding business rules
Rules are the things a new analyst would have to be told. They are not in the schema, but they decide whether an answer is right.
- Test orders live in the data and must be filtered out.
- The EU region uses a different fiscal calendar.
- The
users_v1table is deprecated, useusers_v2.
Write these into the context and the agent applies them automatically instead of producing answers that include test orders or query a dead table.
Adding documentation
Documentation is the plain-language layer. It explains how the business works, what a table is for, and why a column exists. The agent reads it the way it would read a good data dictionary. Notion, Confluence, and Google Drive docs can feed in here, so the knowledge you already wrote does not have to be rewritten.
Why this keeps answers governed
When metrics and rules live in one place, the data team controls what correct means. Nobody can quietly redefine revenue in a single query, because the definition is shared and version controlled. The team edits it once and every agent answer follows.
This is the heart of context engineering. Once the metrics and rules are in place, the next step is testing and evaluating the agent so you know the answers are right before anyone relies on them.