Worka PII
Worka PII is a Rust library for detecting and anonymizing personally identifiable information (PII). It provides deterministic, capability-aware NLP pipelines designed to run on CPU-only environments with explicit auditability and controlled degradation when language features are unavailable.
This crate was extracted from the Worka internal monorepo to become a standalone, reusable component. The APIs and the RFCs are maintained here to support independent development and external adoption.
Features
- Deterministic PII detection with stable byte offsets
- Regex, validator, dictionary, and NER-backed recognizers
- Capability-aware pipeline (tokenization, lemma, POS, NER)
- Configurable anonymization operators (redact, mask, replace, hash)
- Optional Candle-based NER via
candle-nerfeature
Examples
Redaction Example
use ;
use SimpleNlpEngine;
use default_recognizers;
use ;
use Language;
use HashMap;
let analyzer = new;
let text = "Contact Jane at jane@example.com or +1 415-555-1212.";
let result = analyzer.analyze.unwrap;
let mut config = default;
let mut per_entity = new;
per_entity.insert;
per_entity.insert;
config.per_entity = per_entity;
let redacted = anonymize.unwrap;
assert!;
Span Extraction Example
This example keeps the input text intact and uses the detected spans directly.
use SimpleNlpEngine;
use default_recognizers;
use ;
use Language;
let analyzer = new;
let text = "Reach me at jane@example.com from 10.0.0.5.";
let result = analyzer.analyze.unwrap;
for detection in &result.entities
Custom Operators + Audit Log Example
This example applies per-entity operators and emits a simple audit log that records the original value alongside the replacement.
use ;
use SimpleNlpEngine;
use default_recognizers;
use ;
use Language;
use HashMap;
let analyzer = new;
let text = "Email jane@example.com or call +1 415-555-1212.";
let result = analyzer.analyze.unwrap;
let mut config = default;
let mut per_entity = new;
per_entity.insert;
per_entity.insert;
config.per_entity = per_entity;
let anonymized = anonymize.unwrap;
for item in &anonymized.items
Supported Entity Types (Built-in)
The following entity types are supported out of the box via built-in recognizers:
- Phone
- IpAddress (IPv4)
- Ipv6
- CreditCard
- Iban
- Ssn
- Itin
- TaxId
- Passport
- DriverLicense
- BankAccount
- RoutingNumber
- CryptoAddress
- MacAddress
- Uuid
- Vin
- Imei
- Url
- Domain
- Hostname
The following types are supported when a NER engine is enabled:
- Person
- Location
- Organization
Custom Entities and Recognizers
You can add custom entities and recognizers to the pipeline.
use RegexRecognizer;
use EntityType;
let mut recognizers = default_recognizers;
let employee_id = new.unwrap;
recognizers.push;
let analyzer = new;
Custom Pipeline
The pipeline is fully customizable: you can supply your own NLP engine, recognizers, and context enhancers.
- Implement
NlpEngineif you want custom tokenization, lemma/POS, or NER. - Add domain-specific recognizers and context enhancers for tuned detection.
- Swap the default recognizers with your own curated set for strict control.
Language Support and Degradation
The default SimpleNlpEngine is language-agnostic and provides tokenization plus sentence
splitting for any language tag. For EN/DE/ES, you can provide richer language profiles
and context terms to improve recall.
For unsupported languages:
- Regex and validator recognizers still work (language-neutral).
- Lemma/POS/NER capabilities will be absent unless your
NlpEngineprovides them. - Context enhancement falls back to surface terms when lemma is unavailable.
Adding Languages
To add a new language with higher fidelity:
- Implement or integrate an
NlpEnginethat can emit token offsets, lemmas, POS tags, and/or NER. - Provide a
LanguageProfilewith context terms for that language. - Attach those to the analyzer via your pipeline configuration.
Specification
The full specification is in docs/rfc-1200-pii.md and defines the data model, pipeline behavior,
capability reporting, and conformance requirements.
Tests
Benchmarks
Candle NER tests are ignored by default and require --features candle-ner plus a model:
PII_CANDLE_MODEL_DIR=/path/to/model \
You can also set PII_CANDLE_MODEL_ID to download a model via hf-hub.
License
Licensed under either of:
- Apache License, Version 2.0
- MIT license