π Try the demo: https://github.com/LM-Kit/lm-kit-net-samples/tree/main/console_net/document-intelligence/smart-redaction/smart_pii_redaction
Smart Redaction for C# .NET Applications (PII Detection + PDF Redaction)
π― Purpose of the Sample
The Smart Redaction demo shows how to combine two LM-Kit.NET capabilities into one
compliance-ready workflow: PiiExtraction finds personally identifiable information (PII) in a
PDF, and PdfRedactor permanently removes the approved values. A human reviews every suggestion
before anything is removed, so accountability stays with a person, not the model. Everything runs
100% on-device: no cloud, no data leaves the machine.
π₯ Industry Target Audience
- Banking and insurance: redact PII from KYC files, claims, and statements for GDPR reviews.
- Healthcare: remove patient identifiers from records before sharing (HIPAA).
- Legal and government: prepare sensitive documents for disclosure and FOIA responses.
- AI teams: neutralize documents before using them to train or fine-tune models.
π Problem Solved
Drawing a black box over a name in a PDF still ships the name underneath: the text is recoverable by copy-paste, extraction, or raw stream inspection. Manual redaction is also slow and misses occurrences. This sample automates detection and applies true redaction (the underlying data is deleted, not covered), while keeping a human in the loop for the final decision. The result carries no recoverable trace of the removed values.
π» Sample Application Description
The Smart Redaction demo is a console application that:
- Lets you select a model (or paste a custom model URI or model ID)
- Redacts a PDF, or an image (converted to a searchable PDF first); ships a bundled sample document
- Detects PII across every page with a type, confidence score, and bounding boxes
- Presents a human-in-the-loop review where you keep or drop each suggestion
- Permanently removes the approved values and writes a redacted copy
- Verifies the output with a fresh search, proving the values are gone
β¨ Key Features
- On-device PII detection: person, email, phone, address, date of birth, SSN, credit card, bank account, and more
- Confidence scoring: every suggestion carries a confidence value
- Human-in-the-loop review: approve or reject per item, or in bulk (secure default is redact)
- True redaction: text glyphs, image pixels, vector graphics, and annotations are deleted, not covered
- Precise placement: detected occurrences (
TextRegion) feedPdfRedactionArea.FromRegion, so each mark hugs the matched glyphs - Post-redaction verification: confirms the removed values are unrecoverable
Example Output
Detected 8 PII item(s) in 4.2s (overall confidence 0.94).
Review detected PII (human-in-the-loop):
[Enter]/y = redact n = keep a = redact all remaining k = keep all remaining
[1/8] Person "Jane A. Doe" (confidence 0.98, 2 occurrence(s), page 1) redact? [Y/n/a/k] a
...
Approved 8 of 8 item(s) for redaction.
Redaction complete: 96 glyphs and 0 annotation(s) removed across 1 page(s).
Saved: .../account_application_redacted.pdf
Verifying the redacted output (fresh, cache-free search)...
All approved values are unrecoverable by text extraction.
ποΈ Architecture
ββββββββββββββββ βββββββββββββββββββββ ββββββββββββββββ ββββββββββββββββ
PDF β β IDENTIFY β β β REVIEW (human) β β β REMOVE β β β VERIFY β
β PiiExtractionβ β keep / drop each β β PdfRedactor β β PdfSearch β
ββββββββββββββββ βββββββββββββββββββββ ββββββββββββββββ ββββββββββββββββ
entities + approved subset areas + terms 0 matches
occurrences -> true removal
- Identify:
PiiExtraction.Extract(attachment)returnsPiiExtractedEntityitems, each with a type,Value,Confidence, andOccurrences(TextRegionpositions). - Review: a person keeps or drops each suggestion. This is the accountability gate.
- Remove: approved occurrences become
PdfRedactionAreas (viaFromRegion), and the value is also added toSearchTermsas a safety net.PdfRedactordeletes the content. - Verify: a fresh
PdfSearchover the output confirms nothing survived.
βοΈ Getting Started
Prerequisites
- .NET 8.0 SDK or later
- A detection model (default
qwen3.5:4b, ~3.5 GB VRAM or CPU), downloaded automatically on first run. Larger and vision models are offered for higher accuracy and scanned documents. - Optional: a free community license key from lm-kit.com
Download
git clone https://github.com/LM-Kit/lm-kit-net-samples.git
cd lm-kit-net-samples/console_net/document-intelligence/smart-redaction/smart_pii_redaction
Run
dotnet run -c Release
Press Enter to accept the recommended model, Enter again to use the bundled sample (or enter a path
to your own PDF or image), then review each detected item. The redacted PDF is written next to the
input as <name>_redacted.pdf.
π§ Troubleshooting
- Occurrences show "unresolved": the value was detected but not mapped to a page region (common with scanned PDFs). The
SearchTermssafety net still removes it. For scanned files, attach an OCR engine inConfiguration.cs(extractor.OcrEngine = new LMKitOcr();). - Too many or too few detections: tune with domain
Guidance, add aPiiEntityDefinitionfor custom categories, or apply a confidence threshold during review. - Model download is slow the first time: models are cached locally after the first run.
π Extend the Demo
- Add a confidence policy: auto-approve items above a threshold and only prompt for the rest.
- Add custom PII categories (for example internal case numbers or SWIFT codes).
- Batch the pipeline over a folder and write an audit log of what was removed per file.
- Swap the interactive review for an approval queue in a web or desktop app.