Skip to main content

Reversible PII anonymization framework for LLM data pipelines

Project description

carnaval

CI codecov Python Version Checked with mypy License

The art of masking: concealing identity, preserving the essentials.

carnaval is a reversible Python framework for text-document anonymization. It masks sensitive entities (people, organizations, emails, phone numbers, bank identifiers, etc.) before sending them to a cloud LLM, and restores the original values in the structured response (JSON or XML) on the way back.

Status: Stable (Beta) — v0.2.0

  • License: Apache 2.0
  • Stack: Python 3.11 / 3.12 / 3.13, GLiNER (zero-shot NER), regex, AES-256-GCM
  • No external PII framework (no Presidio, no spaCy NER)
  • 184 tests passing, ~95% coverage, mypy-checked, CI on every push
  • Used internally in production at one enterprise (anonymization of supplier acknowledgments before LLM extraction). Public API may evolve until v1.0.

Quick Start

# 1. Installation
git clone <repo>
cd carnaval
python -m venv .venv
source .venv/bin/activate       # Linux/macOS
# or: .\.venv\Scripts\activate  # Windows
pip install -r requirements.txt

# 2. Configuration
cp .env.example .env
# Edit .env and set CARNAVAL_VAULT_PASSWORD=<32+ characters>

# 3. Anonymization
python anonymize.py inbox/my_document.txt --profile acknowledge

# 4. Reinjection (after LLM processing)
python reinject.py response_llm.json --vault outbox/vault/my_document_vault.enc

7-Stage Architecture

Raw TXT --> S1 Intake
        --> S2 Preprocess (language, normalization)
        --> S3 Detect (regex + denylist + GLiNER)
        --> S4 Resolve (dedup, arbitration)
        --> S5 Mask (placeholders + encrypted vault)
        --> S6 Output (6 formats: txt/json/jsonl/xml/conll/html)

JSON/XML --> S7 Reinject --> JSON/XML with original values

Out-of-the-box Business Profiles

Profile Document Type
acknowledge Supplier order acknowledgment
invoice Invoice / professional fee note
email B2B professional email

Private profiles (real client data) in profiles_private/ (git-ignored).

Documentation

Doc Topic
docs/00_overview.md Overview, principles
docs/01_architecture_etages.md The 7 stages in detail
docs/02_install.md Installation
docs/03_deploiement_production.md Production
docs/04_configuration.md YAML config + profiles
docs/05_extension_listes.md Adding entities to mask
docs/06_extension_recognizers.md Coding a new recognizer
docs/07_securite.md Vault, password, audit
docs/08_format_entree_sortie.md Supported formats
docs/09_troubleshooting.md Common errors
docs/10_api_reference.md Python API

Tests

pytest                          # all (except slow)
pytest -m slow                  # real AI tests (downloads GLiNER ~500 MB)
pytest --cov=src/carnaval       # coverage

Contributing

Apache 2.0. Issues and PRs welcome. No personal or client data in public fixtures: use only fictitious entities (Acme Corp, Globex, Initech, etc.).

Project details


Download files

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

Source Distribution

carnaval-0.2.2.tar.gz (1.0 MB view details)

Uploaded Source

Built Distribution

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

carnaval-0.2.2-py3-none-any.whl (1.0 MB view details)

Uploaded Python 3

File details

Details for the file carnaval-0.2.2.tar.gz.

File metadata

  • Download URL: carnaval-0.2.2.tar.gz
  • Upload date:
  • Size: 1.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.6

File hashes

Hashes for carnaval-0.2.2.tar.gz
Algorithm Hash digest
SHA256 55b543dd2c07480f17011da18e72562fcba8a743044c3d11620b8f498b9c3c2b
MD5 f49ab4ca2ebc130df25e0eedb9b726fe
BLAKE2b-256 b8246b2745096d8a2b60fa2e7f0008eaad76bef168dcf8d47281d3f735c2f563

See more details on using hashes here.

File details

Details for the file carnaval-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: carnaval-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 1.0 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.6

File hashes

Hashes for carnaval-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0e9287c2898ef10ad2dc7b76367ab00e0761819899b8f8604e30747ad542f490
MD5 d2dc367c1437a3d63e585141ea3bd8b3
BLAKE2b-256 3e4877ccafd5650711287ccd11d93a538548102cbfa23165ecc879f44a83c5b6

See more details on using hashes here.

Supported by

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