---
title: "Discussion on \"Adding Non-English PII Detection to Kong AI Sanitizer\n\" | Hashnode"
description: "Discussion on \"Adding Non-English PII Detection to Kong AI Sanitizer\n\". How to extend Kong AI Sanitizer with custom languages using Presidio and spaCy. Step-by-step Dutch example with Dockerfile, config, and test results."
url: "https://hashnode.com/posts/adding-non-english-pii-detection-to-kong-ai-sanitizer/69b3dc234c737221668c1932"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Adding Non-English PII Detection to Kong AI Sanitizer](https://deepinkong.hashnode.dev/adding-non-english-pii-detection-to-kong-ai-sanitizer?utm_source=hashnode&utm_medium=feed)

How to extend Kong AI Sanitizer with custom languages using Presidio and spaCy. Step-by-step Dutch example with Dockerfile, config, and test results.

Mar 13 · 10 min read · deepinkong.hashnode.dev  
Read the article

-   [#kong](https://hashnode.com/tag/kong)
-   [#ai-gateway](https://hashnode.com/tag/ai-gateway)
-   [#pii](https://hashnode.com/tag/pii)
-   [#spacy](https://hashnode.com/tag/spacy)
-   [#eu-ai-act](https://hashnode.com/tag/eu-ai-act)
-   [#security](https://hashnode.com/tag/security)
-   [#ai-sanitizer](https://hashnode.com/tag/ai-sanitizer)
-   [#presidio](https://hashnode.com/tag/presidio)

## Written by

[Deepak Grewal](https://hashnode.com/@deepakgrewal)

@deepakgrewal

  
[View profile](https://hashnode.com/@deepakgrewal)

## Responses 2

Markdown supported · ⌘↵ to post

[Deepak Grewal](https://hashnode.com/@deepakgrewal)

[Jun 9](https://hashnode.com/posts/adding-non-english-pii-detection-to-kong-ai-sanitizer/69b3dc234c737221668c1932/comment/6a284029e2fcc9001781e04f)

Great questions, On the round-trip / mapping: you're right that Presidio won't restore on its own. Kong is the wrapper. When it sanitizes the request, it builds a little map of original to redacted value for each entity and keeps it in per-request context (OpenResty's ngx.ctx). On the way back it just does a string replace to swap the originals back in, then throws the map away. It lives for exactly one request. Nothing cached or persisted.

On score being irrelevant without context: there's genuinely no context field, you're right. But score still does something. It's not a firing gate (regex matches or it doesn't), it's a tiebreaker. When two recognizers flag the same span, highest score wins. Built-in Presidio recognizers often sit around 0.85, and the custom default is 0.5, so a custom pattern can lose to a built-in on an overlapping span. If yours "isn't taking effect," bump the score. Just don't treat it as a sensitivity dial. Lower doesn't catch more, higher doesn't suppress weak matches.

On built-in categories having a threshold: they're a fixed list, not individually score-configurable from the plugin. Any actual score\_threshold cutoff lives inside the PII service (Presidio's AnalyzerEngine), not the Kong config, and isn't documented. The plugin applies no cutoff of its own, it just forwards your patterns and scores straight through.

[Akshat Mahla](https://hashnode.com/@akshatmahla)

[Apr 22](https://hashnode.com/posts/adding-non-english-pii-detection-to-kong-ai-sanitizer/69b3dc234c737221668c1932/comment/69e8627be436727814e049ee)

how does replacing the original values that were sanitized from PII plugin work?  
From what I know, presidio only replaces original value back if we tell it what all places it needs to do the replacement. do you have a wrapper to get response from LLM and put the original values back, by keeping a map of values that were sanitized. Also, the custom pattern match has fields: Name, Regex, Score but does not have context field.. without context, the score is irrelevant as regex matches are binary. and for the check box fields of Built-in categories do we have a score defined as some default values ? do these filters have some threshold score..?
