๐ Try the demo:
https://github.com/LM-Kit/lm-kit-net-samples/tree/main/console_net/text-analysis/pii-extraction/batch_pii_extraction
Batch PII Extraction with AI in .NET Applications
๐ฏ Purpose of the Demo
Batch PII Extraction demonstrates how to detect and extract Personally Identifiable Information (PII) from large volumes of documents using LM-Kit.NET. The sample processes files in parallel, applies OCR when needed, and outputs structured JSON results for each document.
It is designed for high-throughput compliance, privacy, and data governance workflows.
๐ฅ Target Audience
- Compliance & Legal โ GDPR, HIPAA, and privacy audits
- Enterprise & B2B Apps โ PII detection pipelines
- Security & Risk โ sensitive data discovery
- Back-office & Ops โ bulk document processing
- Benchmarking & Demos โ throughput and scalability evaluation
๐ Problem Solved
- Manual PII review across thousands of documents
- Mixed input formats including scanned documents
- Scalable extraction with controlled parallelism
- Structured outputs ready for redaction or storage
๐ป Sample Application Description
Console application that:
- Loads a predefined LM-Kit PII extraction model.
- Recursively scans an input directory.
- Runs parallel PII extraction with adaptive thread count.
- Applies OCR automatically for non-text documents.
- Extracts entities such as names, addresses, IDs, and more.
- Writes one JSON output file per input document.
- Displays live progress, throughput, and performance metrics.
๐ Supported Inputs
- PDFs and scanned documents
- Images via OCR (LM-Kit OCR by default)
- Text-based files supported by LM-Kit attachments
๐ Extracted Information
Depending on the model and configuration, extracted entities may include:
- Person names
- Addresses
- Phone numbers
- Email addresses
- National identifiers
- Payment and banking information
- Other sensitive data types (optional)
โ๏ธ Key Features
- โก High-Throughput Batch Processing โ multi-threaded execution
- ๐ง OCR-Aware Extraction โ automatic OCR integration
- ๐ Page-Level Metrics โ documents and pages per second
- ๐ Live Console Dashboard โ progress table with throughput
- ๐งฉ Structured JSON Output โ ready for redaction or analysis
- ๐ Thread-Safe Statistics โ real-time performance snapshots
๐ ๏ธ Getting Started
๐ Prerequisites
- .NET 8.0 or later
- LM-Kit OCR dependencies (default OCR engine)
๐ฅ Download
git clone https://github.com/LM-Kit/lm-kit-net-samples
cd lm-kit-net-samples/console_net/text-analysis/pii-extraction/batch_pii_extraction
โถ๏ธ Run
dotnet build
dotnet run
The sample uses configurable input and output directories and automatically determines the optimal thread count based on hardware and model size.
๐ Output Structure
- One
.jsonfile per input document - Preserves the input folder hierarchy
- JSON includes detected entities and metadata
- Null values omitted for clean output
๐ Runtime Metrics
Displayed during execution:
- Documents processed
- Pages processed
- Per-document processing time
- Documents per second
- Pages per second
Final summary includes total runtime and averages.
๐ Notes
- The model is loaded once and shared across threads.
- Each worker initializes its own extraction engine.
- OCR can be replaced with a custom implementation.
- Additional PII entity definitions can be added programmatically.
- Preferred inference modality can be adjusted for redaction scenarios.
๐ง Extend the Demo
- Add confidence thresholds for filtering results.
- Integrate automatic redaction pipelines.
- Store outputs in databases or object storage.
- Replace OCR with cloud-based engines.
- Combine with document classification or routing workflows.
๐ Related Content
- How-To: Extract PII and Redact Data: Step-by-step guide to detecting and redacting personally identifiable information.
- Glossary: PII Detection: Explains PII detection concepts, entity types, and compliance applications.
- Glossary: Named Entity Recognition: Covers NER concepts that underpin PII extraction.
- PII Extraction Demo: Single-file PII extraction demo with interactive prompts and custom entity definitions.