ContextFence

Open source

Playwright for RAG permissions.

Turn "who can see what" into repeatable tests. ContextFence checks every identity × source boundary in your retrieval layer - so a bad retrieval never reaches a real user. Runs in your CLI and CI.

View on GitHub npm i -D contextfence
contextfence - ci
$ ctxfence run --suite rag
loaded 4 identities · 12 sources
 analyst · finance/*     allowed
 editor · drafts/*       allowed
 guest · public/*        allowed
 guest · finance/q4-memo LEAK

11 passed · 1 failed · exit 1

What it does

Retrieval permissions, tested like any other code.

01

Declare the rules

Describe which identities may retrieve which sources. Plain, versioned config next to your code.

02

Run the matrix

ContextFence probes every identity × source pair against your real retrieval stack, like a browser test.

03

Fail the build

A leak returns a non-zero exit and a clear diff - so it's caught in CI, not by a customer.

rag.fence.tsTypeScript
import { defineSuite } from "contextfence";

export default defineSuite({
  identities: ["analyst", "editor", "guest"],
  rules: {
    guest: { allow: ["public/*"], deny: ["finance/*"] },
  },
  retrieve: myRagPipeline,
});

RUN IT WHERE YOU BUILD

CLI & CI action

Run it locally while you build, then wire the same command into your pipeline as a required check.

WORKS WITH YOUR RETRIEVAL

Stack-agnostic

Point it at any retrieval function - vector DB, hybrid search, or a full RAG chain. MIT licensed.

Fence your context.

Free and open source. Add the check to your repo in a few minutes.