@studio-foundation/anonymizer 0.3.0-beta.6 → 0.4.0-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
# @studio-foundation/anonymizer
|
|
2
2
|
|
|
3
|
-
PII detection and anonymization library
|
|
3
|
+
**Studio** is an agentic pipeline runtime that executes multi-stage LLM workflows with structural validation and automatic retry. This package is the **anonymizer**: a PII detection and anonymization library that replaces sensitive data with consistent tokens before sending to LLMs, with a keymap to restore the original values afterward.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
anonymizer sits at the bottom of the stack, a pure utility with zero `@studio-foundation/*` dependencies. It's usable standalone in any TypeScript project, and it's what powers `anonymize: true` in Studio agent configs.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- Homepage: https://github.com/studio-foundation/studio
|
|
8
|
+
- Full docs: [README](https://github.com/studio-foundation/studio#readme) · [CONCEPTS](https://github.com/studio-foundation/studio/blob/main/CONCEPTS.md)
|
|
9
|
+
- Use via the CLI: [`@studio-foundation/cli`](https://www.npmjs.com/package/@studio-foundation/cli)
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @studio-foundation/anonymizer
|
|
15
|
+
# or
|
|
16
|
+
pnpm add @studio-foundation/anonymizer
|
|
11
17
|
```
|
|
12
18
|
|
|
13
|
-
##
|
|
19
|
+
## Quick start
|
|
14
20
|
|
|
15
21
|
```typescript
|
|
16
|
-
import { anonymize, deanonymize
|
|
17
|
-
import type { PIICategory, PIIDetectionResult, AnonymizerOptions } from '@studio-foundation/anonymizer';
|
|
22
|
+
import { anonymize, deanonymize } from '@studio-foundation/anonymizer';
|
|
18
23
|
|
|
19
24
|
// Anonymize a string
|
|
20
25
|
const { text, keymap } = anonymize('Hi Marie, call me at 555-867-5309');
|
|
@@ -30,11 +35,15 @@ const { text: text2, keymap: keymap2 } = anonymize(nextChunk, { seedKeymap: keym
|
|
|
30
35
|
// PERSON_1 still maps to "Marie" across calls
|
|
31
36
|
```
|
|
32
37
|
|
|
38
|
+
```
|
|
39
|
+
user data → anonymize() → [PERSON_1], [EMAIL_1] → LLM → deanonymize() → original values
|
|
40
|
+
```
|
|
41
|
+
|
|
33
42
|
## PII categories
|
|
34
43
|
|
|
35
44
|
| Category | Token format | What it detects |
|
|
36
45
|
|----------|-------------|-----------------|
|
|
37
|
-
| `person` | `PERSON_N` | Names after salutations (Dear, Hi, Mr., Dr., etc.)
|
|
46
|
+
| `person` | `PERSON_N` | Names after salutations (Dear, Hi, Mr., Dr., etc.) (best effort) |
|
|
38
47
|
| `email` | `EMAIL_N` | Email addresses |
|
|
39
48
|
| `phone` | `PHONE_N` | US phone numbers (10 digits, various formats) |
|
|
40
49
|
| `ssn` | `SSN_N` | Social security numbers (ddd-dd-dddd) |
|
|
@@ -45,9 +54,9 @@ const { text: text2, keymap: keymap2 } = anonymize(nextChunk, { seedKeymap: keym
|
|
|
45
54
|
|
|
46
55
|
Two-phase detection on each call:
|
|
47
56
|
|
|
48
|
-
1. **Regex (high precision)
|
|
57
|
+
1. **Regex (high precision)**: email, phone, SSN, credit card. Structural patterns anchored to avoid false positives (e.g. SSN regex uses strict hyphen format to avoid matching phone fragments).
|
|
49
58
|
|
|
50
|
-
2. **Person names (best effort)
|
|
59
|
+
2. **Person names (best effort)**: salutation-gated pattern (`Dear X`, `Hi X`, `Mr. X`, etc.). Only catches explicitly addressed names, not bare occurrences.
|
|
51
60
|
|
|
52
61
|
Spans are non-overlapping. If two patterns match the same range, the first one wins and the position is marked occupied.
|
|
53
62
|
|
|
@@ -81,10 +90,16 @@ The runner wraps this in `AnonymizationMiddleware` (in `runner/src/middleware/an
|
|
|
81
90
|
2. Tool results are anonymized before being injected back into context
|
|
82
91
|
3. The accumulated keymap is written to `.studio/runs/anonymization/<run-id>.keymap.json` for post-run inspection
|
|
83
92
|
|
|
84
|
-
The middleware is wired by the engine and passed to `runAgent()
|
|
93
|
+
The middleware is wired by the engine and passed to `runAgent()`, user code doesn't call `anonymize()` directly when using the Studio CLI.
|
|
94
|
+
|
|
95
|
+
## For contributors
|
|
96
|
+
|
|
97
|
+
Internal rules that govern this package:
|
|
98
|
+
|
|
99
|
+
- **Zero `@studio-foundation/*` dependencies.** This package must stay a pure utility.
|
|
100
|
+
- `anonymize()` is stateless, the `Tokenizer` is created fresh each call (or seeded via `seedKeymap`).
|
|
101
|
+
- Person detection is always best-effort and non-fatal, failures are silently skipped.
|
|
85
102
|
|
|
86
|
-
##
|
|
103
|
+
## License
|
|
87
104
|
|
|
88
|
-
-
|
|
89
|
-
- `anonymize()` is stateless — the `Tokenizer` is created fresh each call (or seeded via `seedKeymap`).
|
|
90
|
-
- Person detection is always best-effort and non-fatal — failures are silently skipped.
|
|
105
|
+
AGPL-3.0-only
|
package/package.json
CHANGED