Skip to main content

Rule-based PII and secret redaction for Markdown documents — audit log, risk-level filtering, LLM pipeline ready

Project description

markdown-redactor

Rule-based PII and secret redaction for Markdown documents — audit log, risk-level filtering, LLM pipeline ready

Quick start

pip install markdown-redactor
printf "Contact me at jane@example.com\n" | markdown-redactor -

Expected output:

Contact me at [REDACTED]

See docs/GUIDE.md for the full API and CLI usage guide.

Table of contents

Who is this for

  • Teams feeding Markdown documents into LLMs (RAG, agents, chat pipelines)
  • Security-conscious teams that need deterministic redaction before inference
  • Developers who want a small codebase with extensible rules

Key features

  • Pluggable architecture: register custom redaction rules without touching core engine
  • Markdown-aware behavior: by default, skips fenced code blocks and inline code spans
  • Lightweight runtime: zero runtime dependencies
  • Typed API: strict typing-friendly design
  • Operational visibility: per-rule match counters and timing stats

Built-in redaction rules

Default engine includes 24 rules:

  • email, phone
  • ipv4, ipv6
  • us_ssn, us_ein
  • uk_nino
  • in_pan, in_aadhaar, in_gstin
  • br_cpf, br_cnpj
  • iban, swift_bic, eu_vat
  • labeled_sensitive_id (tax ID, driver license, passport, national ID labels)
  • secret_assignment (password/api_key/token style assignments)
  • credential_uri (connection-string credentials)
  • aws_access_key, generic_token, google_api_key, jwt, private_key
  • credit_card (Luhn-validated to reduce false positives)

How redaction works

  1. Markdown text is segmented.
  2. Based on config, non-redactable segments (like fenced code) can be preserved.
  3. Each redactable segment is processed by registered rules in order.
  4. Output and stats are returned.

This makes behavior explicit and easy to extend.

Performance

Runs in $O(n \cdot r)$ time where $n$ is input length and $r$ is active rule count. No network I/O, no AST parsing, no heavy dependencies.

Security and compliance notes

  • This is best-effort pattern redaction, not formal DLP certification
  • Always validate on your real data and threat model
  • Combine with downstream controls (access controls, logging, policy engines)
  • Add organization-specific rules for identifiers, ticket IDs, or internal secrets

Troubleshooting

Nothing is being redacted

  • Verify you are using create_default_engine() or registering custom rules
  • Check whether content is inside fenced/inline code that is skipped by default

Too much is being redacted

  • Tighten custom regex patterns
  • Keep --redact-inline-code / --redact-fenced-code-blocks disabled unless required

CLI command not found

  • Ensure package is installed in active environment
  • Try module mode: python -m markdown_redactor.cli input.md

Additional resources

Development and contribution

See CONTRIBUTING.md for setup and quality checks.

Primary local quality command:

PYTHONPATH=src .venv/bin/python -m ruff check src tests && \
PYTHONPATH=src .venv/bin/python -m mypy src && \
PYTHONPATH=src .venv/bin/python -m pytest

Release process

Maintainers can follow docs/RELEASING.md.

Publishing is automated via .github/workflows/release.yml on tags matching v*. GitHub Release notes and signed provenance attestations are generated via .github/workflows/github-release.yml.

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

markdown_redactor-0.1.4.tar.gz (27.4 kB view details)

Uploaded Source

Built Distribution

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

markdown_redactor-0.1.4-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file markdown_redactor-0.1.4.tar.gz.

File metadata

  • Download URL: markdown_redactor-0.1.4.tar.gz
  • Upload date:
  • Size: 27.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for markdown_redactor-0.1.4.tar.gz
Algorithm Hash digest
SHA256 f7e9e2f9072f9a2b7855f867b0f7ed8b06287dfdaa91c19ddec4f9e3666c2f95
MD5 c00b88a5fd6e8f4d269e20f74766f220
BLAKE2b-256 0670184a0036160f6db641766e055924ef6c4a36eca44a9b70eaaed638274fb7

See more details on using hashes here.

Provenance

The following attestation bundles were made for markdown_redactor-0.1.4.tar.gz:

Publisher: release.yml on jcatama/markdown-redactor

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

File details

Details for the file markdown_redactor-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for markdown_redactor-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e976a4934ec3e95c183424712d1a2fb447dccc86b4d47df01b42e65808e4d023
MD5 420237389dab59aa5b74bf7fbad70205
BLAKE2b-256 4f477e0ccbe88181c15d111a330d5af1f2277c944e6d63387487b74ee44d5bda

See more details on using hashes here.

Provenance

The following attestation bundles were made for markdown_redactor-0.1.4-py3-none-any.whl:

Publisher: release.yml on jcatama/markdown-redactor

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

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