How to evaluate permission-aware RAG systems: a practical engineering guide

By Brainscraft Technologies ·

A retrieval-augmented generation (RAG) application can return a relevant answer and still fail its most important requirement: keeping information within the correct access boundary. For enterprise assistants, retrieval relevance and authorization must be evaluated separately.

Authorize before retrieval

Start with a principal derived from verified server-side authentication. Resolve its tenant and current roles from trusted identity and authorization services. Apply those constraints before ranking documents, and enforce them at the storage or search-query boundary. Filtering only after generation is too late: unauthorized material may already have reached the model, traces or caches.

A small TypeScript reference prepared by Brainscraft Technologies illustrates this ordering with synthetic documents. It filters by tenant and role before lexical token-overlap scoring, returns up to three matching excerpts with source identifiers, and returns an insufficient-evidence status when no authorized document matches. This is a retrieval-stage demonstration, not a full RAG application or a production security guarantee.

Build a reproducible evaluation fixture

Use two tenants with overlapping vocabulary. Tenant A has a staff-accessible travel policy and an administrator-only payroll document. Tenant B has a staff document mentioning travel and payroll. Overlapping terms make the fixture useful: a search engine that ignores permissions could return a highly relevant but unauthorized result.

Synthetic authorization test scenarios
ScenarioExpected result
Tenant A staff searches travelOnly A's travel policy, with its source ID
Unknown tenant searches travelNo evidence
Tenant A staff searches payrollNo evidence
Unrelated queryInsufficient evidence
Principal with no rolesNo evidence
Blank queryRejected
Tenant A administrator searches payrollA's payroll document only

The reference was compiled with TypeScript 5.8.3 and tested with Node.js 22.16.0 on November 27, 2026. All seven synthetic tests passed. Reproduce locally with tsc -p tsconfig.json && node --test test.cjs after cloning the reference repository and running npm ci. No model API or client data is required. The source is available in the public reference repository. This synthetic fixture is intended for learning and review, not production security certification.

Measure the right things

Track unauthorized evidence rate: the number of returned unauthorized document references divided by all returned references. Also track the proportion of requests with any unauthorized evidence, including leakage through logs, caches and citations. A zero rate on a small fixture is necessary but not proof of security. Treat any observed authorization breach as a release blocker.

Measure retrieval recall at k using labeled, authorized relevant documents. Evaluate precision at k separately; a system that retrieves many irrelevant documents can still have high recall. Exclude or separately report queries with no authorized relevant documents when calculating recall. Measure abstention on unanswerable requests and false abstention on answerable ones. For a generative system, separately evaluate whether each material answer claim is supported by its cited evidence. Token overlap is not a calibrated confidence score.

Extend the tests before production

Test revoked permissions, stale indexes, cache keys shared across users, concurrent role changes, forged tenant identifiers, document-level exceptions, and direct document access outside the chat interface. Test malicious instructions embedded in retrieved documents; treat retrieved text as data rather than privileged instructions. Verify that traces and telemetry do not disclose restricted content. Evaluate vector and hybrid retrieval with realistic multilingual queries and document sizes. Repeat authorization checks when fetching source documents and before exposing citations.

Private deployment can reduce some data-transfer risks, but does not replace access controls, encryption, monitoring or incident response. Document the threat model and acceptance criteria before choosing infrastructure.

A practical pilot acceptance gate

Agree on a labeled evaluation set with the customer, define allowed roles and document ownership, and run tests in an isolated environment. Block release on any observed access violation. Set relevance and latency thresholds using representative workloads rather than arbitrary universal targets. Record model, index and policy versions so regressions can be reproduced. Obtain security and business-owner approval before connecting confidential data.

For teams planning an enterprise knowledge assistant, start with the authorization model and evaluation fixture before committing to a model or vector database. Explore private and on-premises RAG development and AI SaaS development at Brainscraft Technologies, or discuss a scoped pilot.