Skip to main content

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 and covered by offline tests. The reference database path is an optional Docker-backed check; this repository does not claim a public CI run.

Quickstart (offline)

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_token configuration 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.

License

Apache License 2.0. See LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ragfence-0.1.0.tar.gz (366.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ragfence-0.1.0-py3-none-any.whl (109.0 kB view details)

Uploaded Python 3

File details

Details for the file ragfence-0.1.0.tar.gz.

File metadata

  • Download URL: ragfence-0.1.0.tar.gz
  • Upload date:
  • Size: 366.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for ragfence-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5baa9f56f86f3c51c094058950ecfc8e6be971dfbd195fc2eca611da224130ac
MD5 c01db5f8b5b823503be467c7025ccd6a
BLAKE2b-256 c94233ba14da5d8da25ef57119540576d85a9ebca6faafb4a8533fd76458727c

See more details on using hashes here.

Provenance

The following attestation bundles were made for ragfence-0.1.0.tar.gz:

Publisher: publish-pypi.yml on eduardbar/RAGfence

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ragfence-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ragfence-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 109.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for ragfence-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dddfbd32dcec2e590149f90b1940e58f8edd3678dc58f7e2d89af35b04f97a45
MD5 d306afecf635b0189fc784833279f030
BLAKE2b-256 1cdd096acd089fde07941eac1b3439c23e2a6251ead1403c6330b9680c821d35

See more details on using hashes here.

Provenance

The following attestation bundles were made for ragfence-0.1.0-py3-none-any.whl:

Publisher: publish-pypi.yml on eduardbar/RAGfence

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.2.0

2 files

This release

0.1.0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page