AI + Analytics

Least-Privilege Data Access for AI Tools: Views, Redaction, Row Limits

By Chinmay Raibagkar·September 6, 2026·10 min read·Some SQL

The 60-second version

Exposing everything is a privacy surface and an accuracy problem at once. The analyst views, tokenisation and caps that narrow the world and improve the answers.

  • What happened, in one line
  • What to do about it this week
  • What you can safely ignore

"Which tables does the AI see?" If the answer is "all of them," you have two problems: a privacy surface you cannot defend and an accuracy problem you cannot fix. Every unnecessary table is both a row of customer data exposed to a third-party API and another chance for the model to join the wrong thing.

Least-privilege data access — exposing the minimum data needed to answer the question — is simultaneously a privacy control and a quality control. This post shows what to expose, what to hide, and the mechanisms (views, redaction, row limits) that enforce it.

The short version: narrow the world, improve the answers

Least Privilege in One Picture

Data Journey
Stage 1The default
Everything exposed

Raw prod tables, PII columns, seven years of history, 400-column events. Maximum surface, maximum confusion.

Maximum risk, minimum accuracy
Stage 2Views + redaction
Curated exposure

Analyst views with fixed grains, PII tokenised, history windowed. The model sees a clean, small, documented world.

Less data, better answers
Stage 3The steady state
Verified + governed

Access logged per question, exposures reviewed quarterly, sensitive columns require explicit elevation.

Defensible and improvable

Least-privilege access means every consumer — human or model — receives the smallest data scope that suffices for its task. For AI analytics the consumer is unusual: it reads schemas to plan, samples rows to understand, and sends context to a third-party API to reason. Each of those three moments needs its own control.

The happy coincidence: everything that reduces exposure also improves accuracy. Fewer tables mean fewer wrong joins. Tokenised PII means the model reasons about segments instead of memorising names. Row limits mean faster, cheaper turns. Privacy and quality are the same project here, not competing ones.


What to expose: the analyst surface

Build a dedicated layer the AI reads instead of production tables:

ExposeHideWhy
Curated views at fixed grains (daily orders, campaign spend)Raw event firehoses and staging tablesFixed grains prevent fan-out and grain confusion at the source
bridging keys (order_id, campaign id, dates)Internal surrogate keys, ETL metadataJoin capability without internals
Aggregated history (13–25 months)Full 7-year historyCovers year-on-year without the scan cost or the stale-schema eras
Tokenised identifiers (stable placeholders)Raw names, emails, phones, addressesGrouping and joining preserved; identity never leaves
Documented metric columns (net revenue, contribution)Ambiguous near-duplicates (gross, total, amount_v2)Removes the trap columns golden-dataset evals keep catching

This is the schema mapping idea enforced as access control rather than documentation: the definition of "revenue" is not just written down, it is the only revenue column the model can reach.


The three enforcement mechanisms

1. Views as the access boundary

The AI's credentials (service account, read-only role) grant SELECT on curated views and nothing else. Raw tables are simply not in its permission set — not hidden by prompt instruction, unreachable by construction. A model cannot leak a table it cannot query, and cannot join one it cannot see.

-- The AI role sees this. It cannot see raw_orders at all.
-- Grain fixed, PII tokenised upstream, history windowed,
-- ambiguous columns excluded by omission.

CREATE VIEW ai_orders_daily AS
SELECT
  DATE(order_created_at, 'Asia/Kolkata') AS day,
  channel,
  state_code,
  COUNT(*) AS orders,
  SUM(net_total) AS net_revenue,
  SUM(contribution_inr) AS contribution,
  COUNT(DISTINCT customer_token) AS customers  -- tokenised, not raw id
FROM internal_orders_enriched
WHERE order_created_at >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 400 DAY)
  AND order_status = 'delivered_paid'
GROUP BY 1, 2, 3;

2. Tokenisation at the boundary

Identifying values are replaced with stable placeholders before reaching the model, and restored on return — grouping, ranking and joining behaviour preserved, identity never transmitted. This is pseudonymisation with a purpose: the model can still answer "top segments by repeat rate" because equal customers map to equal tokens. (DataLens ships exactly this as the "hide identifying values" Privacy setting; the principle generalises to any AI data path.)

3. Row and byte limits as guardrails

Cap what any single turn can pull: bounded sample rows for context, hard byte-scan ceilings on generated queries, dry-run estimates before execution. Limits bound both the privacy blast radius and the cloud bill — the cost post's two-bill problem solved once, structurally.

One quarter after narrowing access

Before vs after
Exposed tables47 → 9 viewsRaw prod access revoked for the AI role
Golden-dataset score54% → 79% exactTrap columns unreachable; wrong joins nearly vanished
PII in model contextZero raw identifiersTokenised; verified by logging sampled prompts
Median query cost−63%Windowed views and byte caps compound
Nobody upgraded the model. The same model, given a smaller and cleaner world, answered better, cheaper, and with nothing to leak. Access design is model performance.

What stays human-gated

Three Access Tiers

Reporting Hierarchy
Tier 1
AI-routine (always on)

Curated views, tokenised identity, windowed history. Answers 90%+ of business questions with zero elevation.

Default scope — reviewed quarterly
Tier 2
AI-elevated (per question)

Finer grains or identified data for a specific approved question, logged with asker, purpose and expiry.

Granted per turn, revoked by default
Tier 3
Human-only (never to models)

Raw PII tables, credentials, payroll, minors' data. No business question asked in chat requires these.

Not in any AI-reachable role, ever

Installing Least Privilege

Process Flow
1

Inventory what the AI role can reach today

List every table, column and row window. The gap between this and the curated list is your current exposure.

2

Build the analyst views

Fixed grains, documented metrics, windowed history. The views from the dedup and normalisation posts are the natural foundation.

3

Tokenise identity at the boundary

Stable placeholders for customers, orders, emails. Verify grouping behaviour survives; verify raw values never transmit.

4

Cap, log and review

Byte caps per query, access logs per turn, quarterly review of the exposure list. Governance is the scheduled part.

Prompts are not access control. "Only query the orders view" in a system prompt is a suggestion the model follows until a long context, an ambiguous question, or a clever rephrase leads elsewhere. If the credential can reach it, assume it will be reached. Enforce in roles, not in prose.


Frequently Asked Questions

Doesn't hiding tables make the AI less capable?

Hiding raw tables while exposing curated views makes it more capable on real questions — the eval data consistently shows wrong-table and wrong-column errors dominating. The capability you lose is answering questions about internals nobody should ask in chat anyway.

How does this interact with bring-your-own-key setups?

Orthogonally and complementarily. BYOK controls where data goes (your contracted provider); least privilege controls what goes there. Either without the other leaves half the surface open — your provider with full prod access, or a least-privilege scope sent to an unvetted endpoint.

What is the smallest version of this a two-person team can do?

A read-only database role with access to five views, tokenised customer identifiers, and a byte-scan cap. An afternoon's work, most of it writing the views you needed for correct reporting anyway. The governance review can be a calendar reminder, not a committee.


Summary & Next Steps

Least privilege for AI analytics means curated views instead of raw tables, tokenised identity instead of raw PII, and caps plus logs instead of hope. It is enforced in database roles, not in prompts — and it improves accuracy at the same time as it reduces exposure.

CR

Chinmay Raibagkar

About author →

Founder of DataLens AI. He helps non-technical teams read their ad and database numbers with confidence — which number to trust, what to do next, and what to ignore.