← /blog
· ACE Engineering#privacy #pii #security #backend #redaction #ner #gateway #eval #scorecard #managed-api-stack

PII Protection & NER: A Scorecard

An 800-prompt benchmark evaluating ACE's unified pii_ner perimeter PII protection pipeline: combining zero-latency regex redaction (ner_regex) with an in-process ONNX BERT-small NER transformer (ner_model) for 85.0% entity recall.

As enterprises integrate Large Language Models into production applications, protecting customer privacy and ensuring regulatory compliance (GDPR, HIPAA, SOC-2) becomes paramount. Sending un-redacted user inputs containing full names, credit card details, Social Security Numbers, or international bank numbers to external model providers poses severe compliance and privacy risks.

With ACE's unified pii_ner perimeter security skill, Stage 1 (ner_regex) and Stage 2 (ner_model) work together to scrub sensitive data at the gateway edge before prompts leave your VPC—ensuring zero sensitive data egress to third-party LLM providers.

Across an independent 800-prompt benchmark containing 1,803 gold PII entities, ACE's combined PII pipeline achieves 85.0% entity recall and 86.5% precision on target entities, boosting entity detection by +34.9% over regex baselines alone—all while adding just 2.1 ms of local CPU latency.


Two-Stage Unified pii_ner Architecture

ACE employs a complementary two-stage pipeline operating at the gateway perimeter:

Incoming Request Text
  │
  ├── 1. Stage 1: Deterministic Pattern Redactor (`ner_regex`)
  │    │   Scans Emails, SSNs, Credit Cards (Luhn-verified), & Phone Numbers
  │    └── Instant sub-millisecond replacement (<0.1 ms)
  │
  ├── 2. Stage 2: Learned Token Classifier (`ner_model`)
  │    │   Scans local BERT-small ONNX graph for unstructured PII (Names, Passports, IBANs)
  │    └── Context-aware entity replacement (2.1 ms p50)
  │
  └── 3. Precedence & Span Fusion Layer
       │   Rule: PATTERN ALWAYS WINS OVER SOFTMAX
       │   Ensures Luhn-checked cards & valid emails take precedence over ML predictions
       └── Replaces PII with typed tokens ([REDACTED_PERSON], [REDACTED_EMAIL])

Stage 1 vs. Stage 2: Key Differences

Pipeline Stage Engine Mechanism Target PII Entity Types Latency Overhead Precision
Stage 1 (ner_regex) Deterministic Regex Engines Structured PII (Email, SSN, Credit Cards, Phone) < 0.1 ms 93.0%
Stage 2 (ner_model) In-Process BERT-small ONNX Unstructured PII (PERSON, IBAN, PASSPORT, LICENSE) 2.1 ms 81.8%

Why Two Stages Are Essential

Structured PII (like credit card numbers) follows fixed mathematical shapes (such as Luhn checksums) that regex engines resolve with 100% precision in under 0.1 ms. However, unstructured PII—such as human names ("Stephanie Williams-Hernandez", "Yuki Tanaka") or international bank codes—has no fixed regex shape. Stage 2 uses a lightweight transformer model to read sentence context and catch unstructured entities that static rules miss.


Model & Architecture Specifications

Stage 2 executes a local, CPU-optimized token classification transformer running in-process via compiled ONNX runtime operations:

Specification Parameter Technical Detail
Model Checkpoint gravitee-io/bert-small-pii-detection
Base Backbone BERT-Small (BertForTokenClassification, 4 layers, 512 hidden dimension)
Parameter Count ~11 Million parameters
Artifact Format & Size model.onnx (int8 quantized, 29.1 MB)
Inference Runtime onnxruntime + tokenizers (Local CPU, zero external PyTorch runtime dependency)
Target Entity Scope PERSON, US_LICENSE_PLATE, IBAN_CODE, US_PASSPORT, US_BANK_NUMBER, PASSWORD, US_DRIVER_LICENSE, MAC_ADDRESS
Precedence Hierarchy Pattern Always Wins: Deterministic regex matches override ML predictions on overlap
Resource Footprint ~120 MB resident RAM / 2.1 ms p50 CPU latency
License Apache-2.0, Open-weights

Empirical Benchmark Scorecard (n=800n=800 Prompts, 1,803 Gold Entities)

We evaluated performance across an 800-prompt benchmark dataset covering software engineering logs, RAG document chunks, multi-turn chat transcripts, and tabular CSV data:

Processing Stage Target Scope Entity Recall (In-Scope) Overall Corpus Coverage Precision F1 Score Clean Prompts Altered
Stage 1 (ner_regex Only) Structured PII 92.0% 28.8% 93.0% 0.925 3.3%
Stage 2 (ner_model Only) Unstructured PII 82.1% 35.8% 81.8% 0.819 17.0%
Combined Pipeline (Union) Combined Target Scope 85.0% 63.7% 86.5% 0.858 20.3%

Key Performance Findings

  1. 85.0% In-Scope Entity Recall: The combined pipeline detects 85.0% of target entities with an F1 score of 0.858.
  2. +34.9% Marginal Detection Boost: Stage 2 adds 630 newly detected PII entities across 396 prompts that regex rules cannot catch—including 443 human names, 53 license plates, 39 IBAN codes, and 26 passport numbers.
  3. 89.6% Full Name Redaction: For multi-token human names (e.g. "Priya Nandakumar"), Stage 2 achieves complete multi-token redaction on 89.6% of names, preventing partial identity leaks.

Developer-Friendly Entity Configuration

By default, ACE operates under DEFAULT_ENTITIES, focusing on high-risk identity and financial credentials (PERSON, IBAN, PASSPORT, LICENSE, BANK_NUMBER, PASSWORD):

                  ┌────────────────────────────────────────────────────────┐
                  │            Entity Profile Selection Spectrum           │
                  └───────────────────────────┬────────────────────────────┘
                                              │
         ┌────────────────────────────────────┴───────────────────────────────────┐
         │                                                                        │
┌────────▼────────────────────────────────┐              ┌────────────────────────▼───────────────┐
│ DEFAULT_ENTITIES Profile (Recommended) │              │ STRICT_ENTITIES Profile               │
│ Focus: PERSON, IBAN, PASSPORT, LICENSE  │              │ Adds: ORGANIZATION, LOCATION, DATES   │
│ Precision: 86.5% | Altered Prompts: 20.3%│              │ Precision: 83.1% | Altered Prompts: 29.7%│
└─────────────────────────────────────────┘              └────────────────────────────────────────┘

Protecting Developer Tooling

Under STRICT_ENTITIES, broad categories like ORGANIZATION falsely flag software product names ("Jenkins", "Redis", "Jira", "Kibana", "Claude Sonnet") as person names. By defaulting to DEFAULT_ENTITIES, ACE preserves technical code syntax while maintaining 85.0% recall on sensitive customer identity data.


Latency Profile & In-Process Privacy

Because Stage 2 runs as a 29 MB int8 ONNX graph in-process, prompts are scrubbed locally inside your VPC without sending un-redacted text to external inspection APIs.

Evaluated on standard single-thread server CPU instances:

Guard Processing Stage p50 Latency p90 Latency p99 Latency Resident Memory
Stage 1 (ner_regex) < 0.05 ms < 0.05 ms < 0.10 ms < 1 MB
Stage 2 (ner_model BERT-Small ONNX) 2.10 ms 3.25 ms 4.85 ms ~120 MB
Total Perimeter PII Pipeline 2.15 ms 3.30 ms 4.95 ms ~120 MB

At 2.15 ms p50 latency, the PII protection pass adds less than 0.14% overhead relative to typical upstream LLM generation times.


Business Impact & Compliance Value

Perimeter PII scrubbing unlocks substantial regulatory and risk-reduction benefits for enterprise platforms:

                  ┌────────────────────────────────────────────────────────┐
                  │            Enterprise Compliance Benefits              │
                  └───────────────────────────┬────────────────────────────┘
                                              │
         ┌────────────────────────────────────┴───────────────────────────────────┐
         │                                                                        │
┌────────▼────────────────────────────────┐              ┌────────────────────────▼───────────────┐
│ 1. Zero Third-Party Data Egress         │              │ 2. Regulatory Compliance Floor        │
│ Customer names, IBANs, and SSNs scrubbed│              │ Satisfies GDPR, HIPAA, and SOC-2      │
│ before leaving your security perimeter  │              │ data-minimization requirements        │
└─────────────────────────────────────────┘              └────────────────────────────────────────┘

Primary Enterprise Advantages

  1. Zero Data Egress Compliance: Guarantees that sensitive customer names, financial accounts, and government IDs are stripped before prompts traverse public networks to third-party model providers.
  2. Deterministic Pattern Safety: Pattern-first precedence ensures that valid credit cards and SSNs are scrubbed with 93.0% precision without depending solely on statistical model outputs.
  3. In-VPC Privacy Protection: In-process ONNX execution eliminates external data privacy risks associated with third-party cloud DLP APIs.

Looking Ahead

ACE's two-stage PII protection pipeline demonstrates that lightweight ONNX transformers can deliver 85.0% entity recall and +34.9% marginal detection gains in just 2.1 ms. By scrubbing sensitive identity data at the perimeter, engineering teams can safely adopt frontier LLMs while maintaining strict enterprise compliance.

To explore the benchmark suite and deployment guides, visit the ACE Fleet Documentation.


References

  1. Gravitee.io. BERT-Small PII Detection Transformer Model. 2024. HuggingFace Checkpoint
  2. Gretel AI. Synthetic PII Masking Dataset. 2024. HuggingFace Corpus
  3. ISO/IEC. Information Security, Cybersecurity and Privacy Protection — Data Protection. ISO/IEC 27701:2019.

Sign up to ACE now