01
Declare the rules
Describe which identities may retrieve which sources. Plain, versioned config next to your code.
ContextFence
Open sourceTurn "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.
npm i -D contextfence$ 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 1What it does
01
Describe which identities may retrieve which sources. Plain, versioned config next to your code.
02
ContextFence probes every identity × source pair against your real retrieval stack, like a browser test.
03
A leak returns a non-zero exit and a clear diff - so it's caught in CI, not by a customer.
import { defineSuite } from "contextfence";
export default defineSuite({
identities: ["analyst", "editor", "guest"],
rules: {
guest: { allow: ["public/*"], deny: ["finance/*"] },
},
retrieve: myRagPipeline,
});RUN IT WHERE YOU BUILD
Run it locally while you build, then wire the same command into your pipeline as a required check.
WORKS WITH YOUR RETRIEVAL
Point it at any retrieval function - vector DB, hybrid search, or a full RAG chain. MIT licensed.
Free and open source. Add the check to your repo in a few minutes.