Skip to main content

retrieval-acl-filter-py

PyPI Python License: MIT

Enforce document ACLs after retrieval and before prompting. Your vector store doesn't know who's asking. Pipe its results through this filter to drop any chunk the current user shouldn't see, before those chunks land in the prompt. Zero runtime dependencies.

Python port of @mukundakatta/retrieval-acl-filter.

Install

pip install retrieval-acl-filter-py

Usage

from retrieval_acl_filter import filter_by_acl, explain_acl_drop

docs = [
    {"id": "public",  "text": "...", "acl": {"public": True}},
    {"id": "team",    "text": "...", "acl": {"groups": ["eng"]}},
    {"id": "personal","text": "...", "acl": {"users":  ["alice"]}},
    {"id": "secret",  "text": "...", "acl": {"groups": ["execs"]}},
    {"id": "no_acl",  "text": "..."},  # missing ACL -> open by default
]

user = {"id": "alice", "groups": ["eng"]}

allowed = filter_by_acl(docs, user)
[d["id"] for d in allowed]   # ["public", "team", "personal", "no_acl"]

# Audit which docs got dropped and why:
report = explain_acl_drop(docs, user)
report[3]   # {"id": "secret", "allowed": False, "reason": "missing_acl_match"}

Custom ACL field name

Some retrievers stamp the ACL field as permissions or similar. Use acl_field=:

filter_by_acl(docs, user, acl_field="permissions")

API

Symbol Behavior
filter_by_acl(docs, user, *, acl_field='acl') Returns the subset of docs user may see.
explain_acl_drop(docs, user, *, acl_field='acl') Per-doc verdict list with id, allowed, reason.

Match semantics (matches the JS sibling)

A document is allowed if any of these is true:

  1. doc.acl.users includes user.id.
  2. doc.acl.groups shares any value with user.groups.
  3. doc.acl.public is True.
  4. The doc has no ACL at all (acl is missing or empty) -- open-by-default.

Otherwise the document is dropped with reason="missing_acl_match".

Heads-up: the open-by-default rule is intentional for back-compat with the JS sibling, but if you're enforcing real ACLs you probably want to flip it. Tag every chunk with an explicit ACL at retrieval time and the open-default never fires.

See the JS sibling's README for the full design notes.

Metadata

Release files for retrieval-acl-filter-py 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for retrieval-acl-filter-py 0.1.0
File Size Uploaded Provenance Actions
retrieval_acl_filter_py-0.1.0.tar.gz 5.8 kB Without provenance Details for retrieval_acl_filter_py-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for retrieval-acl-filter-py 0.1.0
File Interpreter ABI Platform Actions
retrieval_acl_filter_py-0.1.0-py3-none-any.whl Python 3 none any Details for retrieval_acl_filter_py-0.1.0-py3-none-any.whl

Total release size: 11.5 kB

Release files / retrieval_acl_filter_py-0.1.0.tar.gz

Download URL retrieval_acl_filter_py-0.1.0.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5884da368e073c3698ab4f41b70a48821ee02f95c410c1ce57c237bf37292b04
BLAKE2b-256 checksum
How to use checksums
32a2c4fb7e01fa6513794ffe297da5fbc6de1b6ec315884af266a43451d1201c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release files / retrieval_acl_filter_py-0.1.0-py3-none-any.whl

Download URL retrieval_acl_filter_py-0.1.0-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0cfd2617bcabe3e6341aec81f6b9e3e070fd9b17b77a7e46dba73120b4031eef
BLAKE2b-256 checksum
How to use checksums
2631022b775ade0e12046363b4ffe5b191697faff0de137ace5c11cc98355cd8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Security for retrieval-acl-filter-py 0.1.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page