Anonymize textv1.0.0 · JSON Schema
Replaces or transforms detected PII in text using the supplied analysis results and configured anonymization operators.
1. Redact Detected PII Entities with <PII> via Refit
PresidioService.AnonymizeAsync forwards the original text, AnalyzerResponse[] detections, and DEFAULT ReplaceAnonymizer("<PII>") configuration to IPresidioAnonymizer.AnonymizeAsync.
Payload details
text: Original text string containing PII spans.analyzer_results: Array of detections returned byIPresidioAnalyzer.AnalyzeAsync.anonymizers: Dictionary mapping"DEFAULT"or entity names to anonymizer operators (replace,redact,mask,hash, orencrypt).
Example payload
{ "text": "Please contact Minh Nguyen at minh.nguyen@bookworm.dev.", "analyzer_results": [ { "entity_type": "PERSON", "start": 15, "end": 26, "score": 0.85 }, { "entity_type": "EMAIL_ADDRESS", "start": 30, "end": 54, "score": 0.99 } ], "anonymizers": { "DEFAULT": { "type": "replace", "new_value": "<PII>" } }}Using this example
Returns 200 OK with AnonymizerResponse ("text": "Please contact <PII> at <PII>.").
using System.Collections.Frozen;using BookWorm.Chassis.AI.Presidio;using BookWorm.Chassis.AI.Presidio.Clients;
// 1. DI registration via BookWorm.Chassis (PresidioExtensions.AddPresidio)builder.AddPresidio();
// 2. Typed Refit invocation (IPresidioAnonymizer) matching PresidioServicevar anonymizers = new Dictionary<string, ReplaceAnonymizer>{ ["DEFAULT"] = new("<PII>"),}.ToFrozenDictionary();
var request = new AnonymizerRequest(rawText, analyzerResults, anonymizers);AnonymizerResponse result = await anonymizer.AnonymizeAsync(request, cancellationToken);
// 3. Or invoke the combined BookWorm.Chassis facade directlystring sanitized = await presidioService.AnonymizeAsync(rawText, cancellationToken);1{
2 "$schema": "https://json-schema.org/draft/2020-12/schema",
3 "title": "AnonymizeText",
4 "description": "Request to transform text using previously detected PII entities.",
5 "type": "object",
6 "required": ["text", "analyzer_results"],
7 "properties": {
8 "text": {
9 "type": "string",
10 "description": "Text to anonymize."
11 },
12 "anonymizers": {
13 "type": "object",
14 "description": "Optional operators keyed by DEFAULT or a PII entity type.",
15 "additionalProperties": {
16 "oneOf": [
17 {
18 "type": "object",
19 "required": ["type", "new_value"],
20 "properties": {
21 "type": { "const": "replace" },
22 "new_value": { "type": "string" }
23 }
24 },
25 {
26 "type": "object",
27 "required": ["type"],
28 "properties": { "type": { "const": "redact" } }
29 },
30 {
31 "type": "object",
32 "required": ["type", "masking_char", "chars_to_mask"],
33 "properties": {
34 "type": { "const": "mask" },
35 "masking_char": { "type": "string" },
36 "chars_to_mask": { "type": "integer" },
37 "from_end": { "type": "boolean" }
38 }
39 },
40 {
41 "type": "object",
42 "required": ["type"],
43 "properties": {
44 "type": { "const": "hash" },
45 "hash_type": { "type": "string", "enum": ["sha256", "sha512"] }
46 }
47 },
48 {
49 "type": "object",
50 "required": ["type", "key"],
51 "properties": {
52 "type": { "const": "encrypt" },
53 "key": { "type": "string" }
54 }
55 }
56 ]
57 }
58 },
59 "analyzer_results": {
60 "type": "array",
61 "description": "PII detections returned by the Analyzer.",
62 "items": {
63 "type": "object",
64 "required": ["start", "end", "score", "entity_type"],
65 "properties": {
66 "start": { "type": "integer" },
67 "end": { "type": "integer" },
68 "score": { "type": "number" },
69 "entity_type": { "type": "string" }
70 }
71 }
72 }
73 }
74}
75