Level 2: AI layer

Rules in the tool

Tools and guardrails: make wrong requests impossible to express.

A rule written in a prompt can be ignored. A rule built into the tool can't be skipped. Give the model a tool that only accepts valid requests, and have it return a reason instead of a number when it says no.

Updated November 2026Example data, not from a client.
On this page
  1. A prompt is a request, not a rule
  2. Gate 1: the input schema
  3. Gate 2: business rules in code
  4. Gate 3: run as the person asking
  5. Gates 4 and 5: engine and limits
  6. What came back
  7. What I check

Every guardrail in this series so far could be written as a sentence: always use a period, never sum term amounts as revenue, never join the two facts. Put those sentences in a prompt and the model will usually follow them. Usually isn't good enough for a number someone will repeat in a meeting.

A prompt is a request, not a rule

The reliable place for a rule is the tool the model calls. If the tool's input can't express a wrong request, the model can't make one, however the question was phrased. And when the tool says no, it should say why, with no number attached, so there's nothing plausible to repeat.

Diagram · Tools and guardrails: make wrong requests impossible to express

Tools and guardrails: make wrong requests impossible to express A request with metric, dimensions, window and date basis passes five gates. Gate 1, schema check: metric and dimensions from an enum, a required window, no extra fields. Gate 2, business rules: period required, date basis named, term amount never summed. Gate 3, permissions: runs as the asking user with row-level security, read-only. Gate 4: execute via the engine, a MetricFlow query, DAX measure or parameterized SQL, where a validation error stops the run. Gate 5, status and limits: a row cap and a COMPLETE or WITHHELD status. Every gate can reject, which returns a reason and no number. The end is the answer plus a receipt. A tool input schema excerpt shows date_basis as an enum of reporting or accounting and additionalProperties false. THE REQUEST metric · dims · window · date basis 1 · Schema check enum metric and dims, required window, no extra fields pass 2 · Business rules period required, date basis named, term amount never summed pass 3 · Permissions runs as the asking user, row-level security, read-only pass 4 · Execute via engine MetricFlow, DAX or SQL; stops on a validation error pass 5 · Status + limits row cap, COMPLETE or WITHHELD status pass Rejected. Return the reason, no number. Answer + receipt value, status, request, row count Tool input schema (excerpt) "date_basis": { "enum": ["reporting", "accounting"] }, "additionalProperties": false A prompt can't talk its way past a rule in the tool. Example data, not from a client.
Five gates between the request and the answer. Anything that fails a gate gets a reason back, never a number. Example data, not from a client. Open full size

Gate 1: the input schema

Tools for AI models describe their input as JSON Schema. In the Model Context Protocol, for example, every tool carries an inputSchema. That schema is your first gate. Here's the one for the example's revenue tool:

{
  "type": "object",
  "additionalProperties": false,
  "required": [
    "operation",
    "customer_id",
    "product_code",
    "date_basis",
    "period_start",
    "period_end_exclusive"
  ],
  "properties": {
    "operation": {
      "enum": [
        "recognized_revenue"
      ]
    },
    "customer_id": {
      "type": "string",
      "pattern": "^C-[0-9]{3}$"
    },
    "product_code": {
      "type": "string",
      "pattern": "^P-[0-9]{2}$"
    },
    "date_basis": {
      "enum": [
        "reporting",
        "accounting"
      ]
    },
    "period_start": {
      "type": "string",
      "format": "date"
    },
    "period_end_exclusive": {
      "type": "string",
      "format": "date"
    }
  }
}

Every line closes a door. The operation is an enum, so “sum term amounts” isn't a value the model can send. The date basis is required and limited to two values, so the model has to choose. Both period fields are required, so “all time” can't be asked. And additionalProperties: false means a stray field, such as a raw SQL string, is rejected instead of quietly ignored.

One catch: in current JSON Schema, “format” is an annotation unless the validator is set to check it. With the Python validator I used, 2025-02-30 passed as a date until I switched format checking on. Check dates in code as well.

Gate 2: business rules in code

Some rules don't fit in a schema. A period whose start comes after its end is valid JSON. So is a date basis that's allowed for one metric and not another. Those checks go in code that runs before the query, and each one returns a specific reason: “period_start must be before period_end_exclusive,” not “invalid request.”

Gate 3: run as the person asking

The tool should query as the user who asked, so their row-level security applies, and over a read-only connection. Two details catch people out. In Power BI, row-level security applies to workspace Viewers, but not to Admins, Members or Contributors, who can edit the model. Test as a Viewer. And in dbt, Semantic Layer caching (on Enterprise plans) stores cached data separately from the models, and the docs say that when metrics come from the cache, the security context isn't applied to those tables at query time. Don't serve row-restricted metrics from the cache.

Fabric data agents show what built-in versions of this gate look like. The docs say they use the requesting user's credentials, keep read-only connections, keep RLS and column-level security on semantic models, and cap chat responses at 25 rows and 25 columns.

Gates 4 and 5: engine and limits

Once a request passes, the engine writes and runs the query: MetricFlow, a DAX measure, or a parameterized query. Engines validate too. MetricFlow runs explain queries to check that the generated SQL runs and to catch ambiguous join paths. A validation error stops the run and comes back as a reason.

The last gate shapes the answer: a row cap, and the status from part 3. A value only goes out with COMPLETE. Anything else goes out as a status with no number.

What came back

I built a small reference version of this tool on the example data and sent it twelve requests:

Tool outcomes on the example
RequestWhat came back
April 2025, reporting dateCOMPLETE, 100.00
April 2025, accounting dateCOMPLETE, -20.00
July 2025NO_RECORDS_IN_PERIOD, no value
Unknown customer C-999NO_MATCHED_RECORDS, no value
A row with no dateINCOMPLETE_UNKNOWN_PERIOD, no value
A row with no amountINCOMPLETE_AMOUNT, no value
All time (no period)Rejected: 'period_start' is a required property
Sum term amounts as revenueRejected: 'sum_term_amounts' is not one of ['recognized_revenue']
Extra field with raw SQLRejected: Additional properties are not allowed ('sql' was unexpected)
No date basisRejected: 'date_basis' is a required property
Reversed periodRejected: period_start must be before period_end_exclusive
Not a real dateRejected: '2025-02-30' is not a 'date'

Each request was run through a small reference version of this tool on the example data. Example data, not from a client.

Six requests got an answer status, and only the two complete ones carried a number. Six were rejected before any query ran, each with a reason the model can pass on or act on. None of the rejections depended on the model behaving well. They depended on the tool.

The rejections that matter most are the traps from guide 5 and guide 7. “Revenue for all time” fails because a period is required. “Sum the term amounts as revenue” fails because there's no such operation. Those used to be warnings in a document.

What I check in a governed tool

  1. Does the input schema use enums from the catalog, required periods and additionalProperties: false?
  2. Are business rules and dates checked in code, each with a specific reason?
  3. Does every query run as the asking user, read-only, tested as a Viewer?
  4. Does a rejection or incomplete answer return a reason and no number?

Don't ask the model to follow the rules. Build them into the tool.

About to put AI on a Power BI model?

I review one model, fixed scope, and tell you what to fix first.

See the model review

Privacy

Related