Imported from Protocol-Wealth/pw-redact (
AGENTS.md). Install upstream withnpx skills add Protocol-Wealth/pw-redact. Copyright stays with the author.
AGENTS.md — pw-redact
Instructions for AI coding assistants working in this repository.
What This Repo Is
pw-redact is an open-source PII redaction engine for financial services AI pipelines. It strips personally identifiable information from financial text (meeting transcripts, tax notes, mortgage documents) before it reaches AI models, while preserving dollar amounts, percentages, tax brackets, and financial acronyms.
Stack: Python 3.12 · FastAPI · Presidio · spaCy · Fly.io License: MIT Deployment: Configure via fly.toml (not committed)
Key Files
| File | Purpose |
|---|---|
src/pw_redact/main.py |
FastAPI app, routes, middleware, landing page |
src/pw_redact/redactor/engine.py |
Core redaction engine (orchestrates 4 layers) |
src/pw_redact/redactor/regex_patterns.py |
Layer 1: 30 deterministic regex patterns |
src/pw_redact/redactor/presidio_config.py |
Layer 2: Presidio + spaCy NLP setup |
src/pw_redact/redactor/financial_recognizers.py |
Layer 3: CUSIP, account refs, policy numbers |
src/pw_redact/redactor/allow_list.py |
Layer 4: financial data preservation |
src/pw_redact/security/ |
Input validation, injection detection, output validation, rate limiting |
src/pw_redact/rehydrator/engine.py |
Manifest-based placeholder restoration |
tests/ |
332 tests across 9 test files (97% coverage) |
Commands
# Install
pip install -e ".[dev]" && python -m spacy download en_core_web_lg
# Test
pytest tests/ -v
# Lint
ruff check src/
# Run locally
uvicorn pw_redact.main:app --port 8080
# Deploy
fly deploy -a pw-redact --remote-only
Rules
- No real PII. Test fixtures use synthetic data only. Never include real names, SSNs, addresses, or client data.
- MIT license header on every new
.pyfile:# Copyright 2026 Protocol Wealth LLC # Licensed under the MIT License # https://github.com/Protocol-Wealth/pw-redact - Every new regex pattern needs 3+ test cases (match, non-match, extracted text).
- Financial data must survive. Verify allow-list doesn't conflict when adding patterns.
- Security matters. This sits at the chokepoint of an AI pipeline processing SEC-regulated data. Use
hmac.compare_digest()for secrets, validate all external input, use possessive quantifiers in regex to prevent ReDoS. - This is a public repo. No internal URLs, no vendor-specific references, no PW business logic.
- Run tests before committing. All 332 tests must pass. Lint + format must pass. Coverage must stay above 85%.
Architecture
Request → Rate Limiter → Content-Length Guard → Input Validator
→ Injection Detector → Unicode Normalization
→ Layer 1 (Regex) + Layer 2 (Presidio NLP) → Merge/Dedup
→ Layer 3 (Financial Recognizers) → Layer 4 (Allow-List)
→ Placeholder Generation → Output Validator → Response
Adding New Patterns
See CONTRIBUTING.md for detailed instructions.
Quick version:
- Add
_PatternDeftoregex_patterns.py(with score and optional group) - Add tests in
test_regex_patterns.py - Verify allow-list compatibility
- Update README.md "Supported Entity Types" table
- Run
pytest tests/ -v
Document Contexts
| Context | Use for |
|---|---|
general |
Default — core PII detection |
meeting_transcript |
Aggressive name detection + NRP |
tax_return |
EINs, account refs |
financial_notes |
CUSIPs, policy numbers |
mortgage |
NRP + account refs + policy numbers |
real_estate |
Account refs + policy numbers |
Related Documentation
- CLAUDE.md — Detailed build specification and internal notes
- docs/architecture.md — Pipeline deep dive
- docs/deployment.md — Deployment guide
- docs/allow-list-guide.md — Allow-list customization
- SECURITY.md — Vulnerability reporting