zero gravitySOLUTIONS
← All insightsAI & AUTOMATION / REPORTING ARCHITECTURE

Build a read-only AI reporting assistant

QUICK ANSWER

An AI reporting assistant should translate a business question into an approved query plan under a restricted data role. Keep metric definitions, tenant scope, query budgets, and result validation outside the model, then generate an explanation from the verified result and its provenance.

Inside this article 5 sections

A user asks, “Which accounts became active last month?” The hard part is not producing SQL syntax. It is deciding what active means, which accounts the user may see, which time zone defines the month, and whether the data is complete enough to answer.

Build the assistant around an approved reporting surface rather than unrestricted database access. The model interprets the question and proposes a metric request. The application validates that request, executes a permitted plan, and supplies the result for explanation.

Make the business definition an input

Define metrics with a stable identifier, grain, time field, filters, exclusions, and freshness requirements. For account activation, the definition might use the first qualifying completed workflow per account, exclude internal test accounts, and group by a specified reporting calendar. Another organization may define activation differently; the assistant must not choose silently.

Ask for clarification when the requested term maps to several approved definitions. A useful response can offer “accounts that first activated” versus “accounts active at any point.” Those questions are different even if both can be expressed with a count.

{
  "metric": "first_account_activation",
  "metric_version": 4,
  "period": {"start": "2026-10-01", "end_exclusive": "2026-11-01"},
  "reporting_timezone": "UTC",
  "group_by": "plan_tier",
  "scope": "server_resolved_account_scope"
}

This synthetic request contains no arbitrary table name or SQL fragment. The application resolves its scope from the authenticated user and selects the approved query implementation. The model cannot broaden access by changing the scope string.

Constrain the database role and the query language

Use a dedicated role with access only to approved reporting views or tables. A read-only transaction adds a useful restriction, but it is not a complete security or resource boundary. PostgreSQL's read-only mode has defined command restrictions; allowed functions, temporary objects, external effects, and resource use still require deliberate control.

Prefer templates or a constrained query representation for common metrics. If the product permits generated SQL, parse and validate the syntax tree, allowlist relations and functions, prohibit unsupported constructs, and execute under the restricted role. A regular expression looking for the word SELECT is not a query authorization system.

Apply tenant and row visibility independently of the natural-language prompt. Where database policies enforce row access, test the actual runtime role. Avoid giving the assistant a reporting connection that can read every customer's rows and asking it to remember a tenant filter.

Budget scanning and output separately

REPORTING REQUEST / FOUR ENFORCED BOUNDARIES
DEFINITIONApproved metric

Resolve the business meaning and version before querying.

AUTHORITYPermitted scope

Use server-side identity and restricted data access.

EXECUTIONBounded work

Limit time, concurrency, date range, and expensive query shapes.

OUTPUTValidated result

Check grain, freshness, units, and truncation before explanation.

These controls serve different purposes. A small returned table can still require an expensive scan, and a fast query can still expose the wrong rows.

A LIMIT clause bounds returned rows, not necessarily the work needed to produce them. Use statement timeouts, concurrency limits, permitted date ranges, and query-plan review for expensive templates. Consider a reporting replica or warehouse so interactive questions do not compete directly with transactional writes.

The following query shape assumes an approved view with one first-activation row per account and a server-validated tenant parameter. It illustrates a metric implementation, not a complete access policy.

SELECT plan_tier, COUNT(*) AS activated_accounts
FROM reporting.first_account_activation
WHERE tenant_id = $1
  AND activated_at >= $2
  AND activated_at < $3
GROUP BY plan_tier
ORDER BY plan_tier;

Validate parameter types and maximum period length before execution. Do not let the model substitute a SQL expression for a date parameter. If the requested analysis exceeds the interactive budget, offer an asynchronous report with the same permission and provenance rules.

Validate the result before writing the answer

Attach the metric version, query version, source snapshot or freshness watermark, time zone, applied filters, and truncation state to the result. A zero-row result must be distinguishable from a failed query or an empty source partition.

Check expected column types and grain. If a join accidentally duplicates accounts, the result may still be valid SQL with plausible numbers. Compare totals against known invariants or reconciliation checks where available. Avoid letting the model repair suspicious numbers by inventing an explanation.

Generate the narrative from the verified result, and keep calculated percentages in deterministic code when practical. For an illustrative result of twelve activated accounts out of forty eligible accounts, the rate is 30%. The assistant should state the denominator and period, not simply announce “activation improved” without a comparison.

Expose a readable methodology note in the report: definition, period, exclusions, and data age. Users should be able to understand why the answer differs from another dashboard without seeing database implementation details.

Test misleading questions and incomplete data

Include ambiguous metric names, unsupported dimensions, unauthorized account requests, huge date ranges, null values, duplicate source rows, and delayed partitions. Test prompts that ask the assistant to ignore the reporting rules. The query boundary must remain enforced even when the model proposes something invalid.

Verify that a narrative cannot contradict the returned table or claim causality from a descriptive comparison. If the data shows a difference between plan tiers, that does not establish why the difference exists. Preserve uncertainty and suggest the next analysis where appropriate.

The metric governance guide establishes definitions, and tenant isolation guidance explains independent access boundaries. Our AI integration work connects those principles to reporting over your business data.

FROM INSIGHT TO ACTIONAI-native implementation

Connect AI reporting to trustworthy business definitions.

We help build reporting assistants with scoped queries, validated results, and explanations tied to the metrics your organization actually uses.

Explore AI implementationDiscuss your AI workflow

Start with your goals.
We’ll work through the next step together.