Skip to main content

RAGFence

CI PyPI Python License Security policy

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.

RAGFence evaluation report sample

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_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.

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.

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.2.0.tar.gz (403.2 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.2.0-py3-none-any.whl (118.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for ragfence-0.2.0.tar.gz
Algorithm Hash digest
SHA256 77fcaa38b670227ee4eb7426cb7cb67b614959e9a7e43e1e7b615db7ae9c41cb
MD5 17181c3ef7722ae5eb789622da3b8317
BLAKE2b-256 634a0a217473fabfb8b122bfb23a10c5b3e0580fe14136376efab6cbabba0fb4

See more details on using hashes here.

Provenance

The following attestation bundles were made for ragfence-0.2.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.2.0-py3-none-any.whl.

File metadata

  • Download URL: ragfence-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 118.2 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4e8dacb8a3da981546286c0b8a34a6df8987ad10d7f0b191d97a9bda050e15e6
MD5 bfc74d99ec77d5ff0f5287576149eb7b
BLAKE2b-256 cd8caea88827781d8b52ef2eb02ad3d6bc011b5ac7bf0d09743540c99e7d900a

See more details on using hashes here.

Provenance

The following attestation bundles were made for ragfence-0.2.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

This release

0.2.0 This release

2 files

0.1.0

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