RAGFence
Security testing and authorization-aware retrieval for production RAG systems.
RAGFence is a Python library and CLI that helps teams build and verify RAG
pipelines that never leak. It provides authorization-aware retrieval primitives,
a deterministic evaluation engine, and the generic_http adapter for testing an
external RAG target.
Status: v0.1.0 — production-ready release. The evaluation and adapter contracts are implemented, covered by offline tests, and validated against a live PostgreSQL/pgvector reference environment in CI.
Quickstart from PyPI
pip install ragfence
ragfence init
ragfence test # gate pass/fail; exit code 0 = passed
Quickstart (offline, development)
Requires Python >= 3.12. The offline quickstart needs no Docker, PostgreSQL, network access, API keys, or other external services.
python -m venv .venv
.venv\Scripts\python -m pip install -e ".[dev]" # Windows
# source .venv/bin/activate && pip install -e ".[dev]" # POSIX
Check the installed CLI, initialize a local project, and run the deterministic reference evaluation:
ragfence --help
ragfence init
ragfence test
The human-readable report is written to .ragfence/reports/latest.txt and the
machine-readable report is written with:
ragfence test --json
which writes .ragfence/reports/latest.json. Use --output PATH to write the
report to an explicit destination. Exit codes are:
- 0 = completed evaluation meets the configured threshold (gate passed).
- 1 = completed evaluation is below the threshold (gate failed).
- 2 = configuration, usage, reachability, or runtime failure.
Run the repository quality gates without Docker or other external services:
python -m pytest
ruff check .
ruff format --check .
mypy
Optional Docker database checks
Docker Compose is optional and only needed for database-backed reference checks. It starts PostgreSQL 16 with pgvector; it is not required by the offline tests or the generic HTTP adapter tests:
docker compose up -d
Use ragfence init --up to start, migrate, seed, and embed the reference DB in
one step. When installed from a wheel (outside this repository), init --up
uses the reference environment bundled inside the package — no checkout
required. Use ragfence adapter check reference to verify connectivity,
migration state, and seed completeness against a running database.
Safe starting points for configuration are examples/reference.toml
and examples/generic_http.toml. The latter uses
CHANGEME and localhost placeholders only.
Production evaluation path
The production reference evaluation executes a declarative control matrix of 8 controls against the reference adapter (DB-resolved identities, RetrievalService and DbVectorStore/pgvector):
| Control | Category | Expected behavior |
|---|---|---|
same-tenant-authorized |
positive | MUST_ALLOW |
same-tenant-no-permission |
negative | MUST_BLOCK |
cross-tenant |
negative | MUST_BLOCK |
cross-department |
negative | MUST_BLOCK |
explicit-allowlist |
positive | MUST_ALLOW |
soft-deleted-document |
negative | MUST_BLOCK |
public-same-tenant |
positive | MUST_ALLOW |
insufficient-clearance |
negative | MUST_BLOCK |
Each control result has one of four statuses: PASS, FAIL,
INCONCLUSIVE, or SKIPPED. A single EvaluationGate fails closed for
required failures, required inconclusive controls, missing coverage, missing
identity/retrieval evidence, target errors, or threshold failure. The gate
reports three scores: security_score, utility_score, and overall_score
(mean of the two, computed over executed required controls only). The JSON
report includes per-control results, the three scores, gate_passed,
gate_reason, and outcome (exactly "pass" on healthy runs). The report
declares real_provider_used: false because the production matrix path uses no
external provider.
The legacy v0.1 generation-skip semantics (no_real_provider) apply only to the
legacy engine path and never to the production matrix path.
External identity strategies
The generic_http adapter represents identity only through explicit
configuration. Two identity strategies are supported:
- Header templates: interpolate an allowlisted set of actor placeholders
(
{actor_user_id},{actor_tenant_id},{actor_department_id}) into configured request headers. - Bearer token: uses the
auth_tokenconfiguration value (set via environment variable for secrets).
Identity-dependent controls without a configured strategy are INCONCLUSIVE and the gate fails. Secrets are redacted from reports, findings, reasons, and errors.
Documentation
See the documentation index for the product, technical, application-flow, schema, implementation-plan, and UI/UX documents.
Use in your CI
Evaluate any pull request with the first-party action:
jobs:
security-eval:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: eduardbar/RAGfence@v1 # this repository's composite action
with:
adapter: reference # or generic_http + base-url + start-target-command
threshold: '80'
The action provisions its own pgvector service, uploads the JSON report as an artifact, and fails the job when the evaluation gate fails (fail closed).
License
Apache License 2.0. See LICENSE.
Metadata
Release files for ragfence 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ragfence-0.2.0.tar.gz | 403.2 kB | With provenance | Details for ragfence-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ragfence-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for ragfence-0.2.0-py3-none-any.whl |
Total release size: 521.4 kB
Release files / ragfence-0.2.0.tar.gz
| Download URL | ragfence-0.2.0.tar.gz |
|---|---|
| Size | 403.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
77fcaa38b670227ee4eb7426cb7cb67b614959e9a7e43e1e7b615db7ae9c41cb
|
|
BLAKE2b-256 checksum How to use checksums |
634a0a217473fabfb8b122bfb23a10c5b3e0580fe14136376efab6cbabba0fb4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 22, 2026.
Transparency logRelease files / ragfence-0.2.0-py3-none-any.whl
| Download URL | ragfence-0.2.0-py3-none-any.whl |
|---|---|
| Size | 118.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4e8dacb8a3da981546286c0b8a34a6df8987ad10d7f0b191d97a9bda050e15e6
|
|
BLAKE2b-256 checksum How to use checksums |
cd8caea88827781d8b52ef2eb02ad3d6bc011b5ac7bf0d09743540c99e7d900a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 22, 2026.
Transparency logSecurity for ragfence 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for ragfence-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 22, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.