Privacy-first hybrid AI document fingerprinting
DocuScope AI is a local-first document intelligence project that scans folders and subfolders, processes multiple file types, extracts useful document signals, masks sensitive data, and generates sanitized document fingerprints for reporting and review.
DocuScope AI started from a personal need: I wanted a way to search through my own files and quickly find specific information without manually opening and reviewing every document one by one.
It also serves as a practical learning project to help me understand how AI can be integrated into software in a useful, structured, and privacy-conscious way — and to practice building it the way an AppSec-minded engineer would: threat model the AI layer explicitly, guard against malicious/adversarial input, and never let an optional enhancement (AI) compromise the reliability or privacy guarantees of the deterministic core.
Phase 1 built the deterministic MVP foundation: folder scanning, parser integration, OCR support, privacy-aware sanitization, rules-based classification, structured export, and automated testing.
Phase 2 replaced the AI placeholders with a real, provider-abstracted Anthropic Claude integration, added concrete resource-exhaustion guards against malicious/adversarial documents, and added a local FastAPI demo UI. See Roadmap for what's next.
Selected Folder
-> File Scanner
-> Resource Guards (size / zip-bomb / page-count / pixel-count limits)
-> Parser / OCR
-> Privacy Redaction Layer
-> AI Enrichment Layer (rules-first, Claude fallback on sanitized text only)
- rules + AI classification
- rules + AI extraction
- AI sanitized summary (PII-checked before use)
-> Confidence + Review Flag
-> JSON + Excel Report
-> Optional SQLite
-
recursive folder scanning
-
support for:
- DOCX
- XLSX
- TXT
- JPG
- PNG
-
PDF text extraction
-
OCR for images
-
OCR fallback for scanned PDFs
-
file metadata extraction
-
privacy masking and sanitization
-
rules-based classification, with a real Claude-backed AI fallback
-
structured extraction, with a real Claude-backed AI fallback
-
AI-generated sanitized summaries, with a deterministic template fallback
-
confidence scoring
-
review flagging
-
resource-exhaustion guards (oversized files, zip bombs, PDF page-count bombs, image decompression bombs)
-
JSON export
-
Excel export
-
optional SQLite persistence
-
local FastAPI demo app
-
automated tests (including adversarial/security-focused fixtures)
- NER-based PII detection (names, addresses, free-text PII) — current detection is pattern/regex-based; see Roadmap
- semantic near-duplicate detection
- advanced signature/stamp detection
- enterprise-grade access controls / API authentication
- production deployment
- packaged macOS desktop app
DocuScope AI is designed to avoid exposing sensitive data unnecessarily.
- sensitive values are masked before anything (rules, AI, exports) sees the text
- the AI fallback layer only ever receives already-sanitized text — raw document content never leaves the deterministic pipeline
- AI-generated output is itself re-checked for PII-shaped content before being used, verifying that redaction actually held
- outputs are sanitized
- the project remains local-first by design
The system separates:
- deterministic software engineering tasks (rules-based classification, regex extraction, template summaries)
- AI-powered interpretation tasks (an Anthropic Claude fallback, used only when the deterministic path is low-confidence or empty)
The AI layer sits behind a small provider-agnostic interface (app/ai/provider.py), so it degrades to the deterministic logic automatically whenever no API key is configured or a call fails — the pipeline never depends on AI to function.
The project is intentionally built to run locally:
- easier to debug
- lower cost
- better privacy control
- ideal for learning and portfolio development
.pdf.docx.xlsx.txt.jpg.jpeg.png
Rules-first classification (with an AI fallback) supports:
invoicereceiptcontractresumebank_statementtax_documentformletterunknown
For each supported file, DocuScope AI currently:
- scans the selected folder recursively
- identifies supported documents
- rejects files that trip a resource-exhaustion guard (oversized, zip-bomb-shaped, too many PDF pages, decompression-bomb image)
- extracts file metadata
- parses text/content
- applies OCR when needed
- detects basic sensitive data patterns
- masks sensitive values
- classifies the document (rules first, Claude fallback if low-confidence)
- extracts structured fields (regex first, Claude fallback if empty)
- generates a sanitized fingerprint and summary
- computes confidence and review status
- exports results to JSON, Excel, and optionally SQLite
DocuScope AI is built to generate sanitized fingerprints, not raw document dumps.
Examples of privacy-safe behavior:
- emails, phone numbers, and IDs are masked before any downstream processing
- the AI fallback layer never receives raw/unmasked text
- AI output is validated against a schema and re-scanned for PII-shaped content before use
- summaries are sanitized
- reports are intended for structured review, not raw content exposure
See SECURITY.md for the full threat model, including prompt-injection and resource-exhaustion mitigations.
docuscope-ai/
│
├── app/
│ ├── main.py # thin CLI entrypoint
│ ├── pipeline.py # shared orchestration (scan -> fingerprint -> export), used by CLI and API
│ ├── config.py # env-driven settings (.env)
│ ├── models/
│ │ └── fingerprint.py
│ ├── scanner/
│ │ └── folder_scanner.py
│ ├── security/
│ │ └── resource_guards.py # zip-bomb / page-count / pixel-count / file-size guards
│ ├── parsers/
│ │ ├── pdf_parser.py
│ │ ├── docx_parser.py
│ │ ├── xlsx_parser.py
│ │ ├── txt_parser.py
│ │ └── image_parser.py
│ ├── ocr/
│ │ └── ocr_service.py
│ ├── privacy/
│ │ ├── pii_detector.py
│ │ ├── masker.py
│ │ └── sanitizer.py
│ ├── classify/
│ │ ├── rules_classifier.py
│ │ ├── ai_classifier.py
│ │ └── constants.py
│ ├── extract/
│ │ ├── regex_extractors.py
│ │ └── ai_extractor.py
│ ├── summarize/
│ │ └── ai_summarizer.py
│ ├── ai/ # provider-agnostic AI layer (Anthropic Claude implementation)
│ │ ├── provider.py
│ │ ├── anthropic_provider.py
│ │ ├── prompts.py
│ │ └── schemas.py
│ ├── api/ # local FastAPI demo
│ │ ├── server.py
│ │ ├── schemas.py
│ │ └── static/index.html
│ ├── confidence/
│ │ └── scoring.py
│ ├── export/
│ │ ├── json_exporter.py
│ │ └── excel_exporter.py
│ ├── storage/
│ │ └── sqlite_store.py
│ └── utils/
│ └── text_utils.py
│
├── outputs/
├── tests/
├── .env.example
├── requirements.txt
├── pytest.ini
└── README.md
python3.11 -m venv .venv
source .venv/bin/activatepip install -r requirements.txtbrew install tesseract
brew install popplersudo apt-get update
sudo apt-get install -y tesseract-ocr poppler-utilscp .env.example .envFill in ANTHROPIC_API_KEY to enable the real Claude fallback layer. Leaving it empty is fully supported — the pipeline runs entirely on the deterministic rules/regex/template logic, with zero external calls and zero cost.
python -m app.main --input "/path/to/folder" --output "./outputs" --sqlite--input→ folder to scan--output→ output folder--sqlite→ save sanitized results into SQLite
DocuScope AI includes a minimal local FastAPI demo.
uvicorn app.api.server:app --reloadThen open http://127.0.0.1:8000 to:
- enter a folder path
- run a scan
- view sanitized results (classification, PII flags, summary, review status)
This is a local, single-operator demo tool — no authentication is included, and it should not be exposed to a network. See SECURITY.md for details.
One sanitized JSON fingerprint per processed document.
A flattened report of processed documents.
Optional sanitized record storage for local querying.
Run all tests:
pytest -qRun verbose tests:
pytest -vThe suite includes adversarial/security-focused fixtures (zip-bomb-shaped DOCX/XLSX, PDF page-count bombs, image decompression bombs, and a simulated prompt-injection payload) alongside the functional tests. All AI-layer tests mock the Anthropic client — no live API calls are made in CI.
- NER-based PII detection (names, addresses, free-text PII) is not yet implemented — detection today is pattern/regex-based
- duplicate detection is exact-hash only
- language detection is heuristic
- signature/stamp detection is not fully implemented
- the FastAPI demo has no authentication (by design, for a local single-operator tool)
- no production deployment yet
- no packaged macOS desktop app yet
- NER-based PII detection (Presidio + spaCy), as an opt-in layer alongside the existing regex detector
- improve duplicate detection (semantic near-duplicate, not just exact-hash)
- improve structured extraction
- improve review workflow
- improve local UI
- package for macOS
- harden for production scenarios (auth, deployment)
He-Isa
DocuScope AI — Privacy-first hybrid AI document fingerprinting