<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: glastor-core</title>
    <description>The latest articles on DEV Community by glastor-core (@andres_003352671e0820b880).</description>
    <link>https://dev.to/andres_003352671e0820b880</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4254370%2Fb0d7b6d0-f120-49c4-93b2-6ee423f98261.png</url>
      <title>DEV Community: glastor-core</title>
      <link>https://dev.to/andres_003352671e0820b880</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/andres_003352671e0820b880"/>
    <language>en</language>
    <item>
      <title>How We Built a 165 µs Reversible PII Anonymizer for LLMs &amp; MCP in Rust (212x Faster Than Presidio)</title>
      <dc:creator>glastor-core</dc:creator>
      <pubDate>Thu, 19 Nov 2026 19:57:20 +0000</pubDate>
      <link>https://dev.to/andres_003352671e0820b880/how-we-built-a-165-us-reversible-pii-anonymizer-for-llms-mcp-in-rust-212x-faster-than-presidio-25a0</link>
      <guid>https://dev.to/andres_003352671e0820b880/how-we-built-a-165-us-reversible-pii-anonymizer-for-llms-mcp-in-rust-212x-faster-than-presidio-25a0</guid>
      <description>&lt;p&gt;Every time an AI agent, RAG pipeline, or MCP tool sends a prompt to an external LLM API, there is a high chance it carries sensitive data: customer emails, credit card numbers, IBANs, national tax IDs, PostgreSQL connection strings, or leaked API keys.&lt;/p&gt;

&lt;p&gt;Most teams try to solve this in one of two ways:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Python NLP pipelines (like Microsoft Presidio + spaCy)&lt;/strong&gt;: ~35 ms per prompt, ~450 MB RAM footprint, and &lt;strong&gt;no native support for restoring streamed SSE tokens&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cloud DLP APIs (like AWS Comprehend PII)&lt;/strong&gt;: 80–250 ms of network latency, \$100+ per million requests, and you still have to send raw PII over the wire to a third-party cloud.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;At &lt;strong&gt;&lt;a href="https://glastor.es" rel="noopener noreferrer"&gt;GLASTOR®&lt;/a&gt;&lt;/strong&gt;, we needed sub-millisecond, zero-egress, &lt;strong&gt;reversible&lt;/strong&gt; PII protection that works inline with &lt;strong&gt;OpenAI/Anthropic SSE streams&lt;/strong&gt; and &lt;strong&gt;Model Context Protocol (MCP)&lt;/strong&gt; agents.&lt;/p&gt;

&lt;p&gt;So we built &lt;strong&gt;&lt;a href="https://github.com/glastor-core/pii-veil" rel="noopener noreferrer"&gt;&lt;code&gt;pii-veil&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt; in Rust — and you can test it right now in your browser (100% client-side WebAssembly, zero data leaves your device):&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;Live WASM Playground:&lt;/strong&gt; &lt;a href="https://pii-veil.pages.dev" rel="noopener noreferrer"&gt;https://pii-veil.pages.dev&lt;/a&gt;&lt;br&gt;&lt;br&gt;
👉 &lt;strong&gt;Open-Source Repository:&lt;/strong&gt; &lt;a href="https://github.com/glastor-core/pii-veil" rel="noopener noreferrer"&gt;https://github.com/glastor-core/pii-veil&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  The Hard Problem: Reversible Streaming Restoration
&lt;/h2&gt;

&lt;p&gt;Redacting an outgoing prompt is only half the problem. If you replace &lt;code&gt;maria@startup.io&lt;/code&gt; with &lt;code&gt;[EMAIL_1]&lt;/code&gt; and &lt;code&gt;4532-0151-1283-0366&lt;/code&gt; with &lt;code&gt;[CREDIT_CARD_1]&lt;/code&gt;, the LLM responds using those semantic placeholders:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;"Invoice sent to &lt;code&gt;[EMAIL_1]&lt;/code&gt; for card &lt;code&gt;[CREDIT_CARD_1]&lt;/code&gt;."&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In production, LLMs stream responses token-by-token over Server-Sent Events (SSE). A placeholder like &lt;code&gt;[EMAIL_1]&lt;/code&gt; frequently arrives &lt;strong&gt;split across chunk boundaries&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Chunk 1: "Invoice sent to [EMA"
Chunk 2: "IL_1] for card [CREDIT_"
Chunk 3: "CARD_1]."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Naive regex replacement breaks immediately on split chunks. &lt;code&gt;pii-veil&lt;/code&gt; solves this with &lt;code&gt;StreamingRestorer&lt;/code&gt;, a state-machine buffer that detects partial placeholder prefixes at chunk boundaries and restores them in &lt;strong&gt;69.65 µs per SSE chunk&lt;/strong&gt; without buffering the entire response.&lt;/p&gt;




&lt;h2&gt;
  
  
  Benchmarks: &lt;code&gt;pii-veil&lt;/code&gt; vs. Presidio vs. AWS Comprehend
&lt;/h2&gt;

&lt;p&gt;Measured on standard x86_64 hardware using Rust's &lt;code&gt;criterion&lt;/code&gt; statistical harness (reproducible via &lt;code&gt;cargo bench -p pii-veil-core --bench bench_throughput&lt;/code&gt;):&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Metric / Capability&lt;/th&gt;
&lt;th&gt;🛡️ GLASTOR® &lt;code&gt;pii-veil&lt;/code&gt;
&lt;/th&gt;
&lt;th&gt;🐍 Microsoft Presidio&lt;/th&gt;
&lt;th&gt;☁️ AWS Comprehend&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Typical Prompt Latency (1 KB, 7 entities)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;165.68 µs (0.165 ms)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;~35 ms&lt;/td&gt;
&lt;td&gt;~140 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Single-Entity Scan Latency&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;4.01 µs&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;~12 ms&lt;/td&gt;
&lt;td&gt;~90 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;1 MB Throughput Buffer&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;20.58 ms (~46.3 MiB/s)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;~4,200 ms (4.2 s)&lt;/td&gt;
&lt;td&gt;Not supported&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Speedup&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Baseline (1x)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;~212x faster&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;~848x faster&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;SSE Streaming Restoration&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;69.65 µs / chunk&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;❌ Not supported&lt;/td&gt;
&lt;td&gt;❌ Not supported&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Memory Footprint&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;&amp;lt; 15 MB (Distroless)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;~450 MB (spaCy)&lt;/td&gt;
&lt;td&gt;Cloud Service&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Cost per 1M Requests&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;\$0.00 (Self-Hosted)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Compute cost&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;\$100.00+ USD&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Why is it ~212x faster?
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Presidio: Prompt -&amp;gt; Python -&amp;gt; spaCy NLP -&amp;gt; Tokenizer -&amp;gt; Non-SIMD Regex -&amp;gt; Copies [25–60 ms]
pii-veil: &amp;amp;str -&amp;gt; Rust Zero-Copy Slices -&amp;gt; Aho-Corasick SIMD Pre-Filter -&amp;gt; Checksum Validators -&amp;gt; In-Place Vault [0.16 ms]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of loading a 450 MB ML model to detect structured PII and secrets, &lt;code&gt;pii-veil&lt;/code&gt; combines &lt;strong&gt;SIMD-accelerated &lt;code&gt;aho-corasick&lt;/code&gt; pre-filtering&lt;/strong&gt; with &lt;strong&gt;18 detectors backed by mathematical checksums&lt;/strong&gt; (Luhn for credit cards, ISO 13616 Mod-97 for IBANs, Mod-23 for Spain DNI/NIE, Mod-11 for Argentina CUIT/CUIL and Chile RUT) to eliminate false positives.&lt;/p&gt;




&lt;h2&gt;
  
  
  Drop-In Usage: CLI, Proxy, MCP &amp;amp; GitHub Actions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Redact &amp;amp; Restore with an Authenticated Encrypted Vault
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;veil redact \
  --text &lt;span class="s2"&gt;"Charge maria@startup.io (CUIT 20-12345678-6) on card 4532-0151-1283-0366"&lt;/span&gt; \
  --vault-out vault.enc \
  --vault-pass &lt;span class="s2"&gt;"my-secret-passphrase"&lt;/span&gt;

veil restore \
  --text &lt;span class="s2"&gt;"Invoice sent to [EMAIL_1] (tax ID [NATIONAL_ID_1]) for card [CREDIT_CARD_1]."&lt;/span&gt; \
  --vault vault.enc \
  --vault-pass &lt;span class="s2"&gt;"my-secret-passphrase"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Built-in HTTP/SSE Proxy &amp;amp; MCP Server
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;veil proxy --listen 127.0.0.1:8080 --echo&lt;/code&gt;&lt;/strong&gt;: Transparently redacts outgoing LLM JSON payloads and restores incoming &lt;code&gt;text/event-stream&lt;/code&gt; SSE responses.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;veil mcp&lt;/code&gt;&lt;/strong&gt;: Zero-dependency JSON-RPC 2.0 MCP server over &lt;code&gt;stdio&lt;/code&gt; exposing &lt;code&gt;veil_redact&lt;/code&gt;, &lt;code&gt;veil_restore&lt;/code&gt;, &lt;code&gt;veil_redact_json&lt;/code&gt;, and &lt;code&gt;veil_scan&lt;/code&gt; directly to Claude Desktop, Cursor, and Windsurf.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. CI/CD DLP Gatekeeper (&lt;code&gt;glastor-core/pii-veil@v1&lt;/code&gt;)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;🛡️ PII &amp;amp; Secret DLP Audit&lt;/span&gt;
  &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;glastor-core/pii-veil@v1&lt;/span&gt;
  &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"."&lt;/span&gt;
    &lt;span class="na"&gt;exclude&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"examples,tests"&lt;/span&gt;
    &lt;span class="na"&gt;fail-on-detect&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"true"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Try It in 3 Seconds
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Live WASM Demo (zero backend):&lt;/strong&gt; &lt;a href="https://pii-veil.pages.dev" rel="noopener noreferrer"&gt;https://pii-veil.pages.dev&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GitHub Repo &amp;amp; Multi-Language SDKs (Rust, Python, Node.js, Go):&lt;/strong&gt; &lt;a href="https://github.com/glastor-core/pii-veil" rel="noopener noreferrer"&gt;https://github.com/glastor-core/pii-veil&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Follow the open-source ecosystem:&lt;/strong&gt; &lt;a href="https://github.com/glastor-core" rel="noopener noreferrer"&gt;@glastor-core on GitHub&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Engineered by *&lt;/em&gt;&lt;a href="https://glastor.es" rel="noopener noreferrer"&gt;GLASTOR®&lt;/a&gt;** — High-Performance Rust Systems, AI Infrastructure &amp;amp; DevSecOps Engineering. Need on-premise air-gapped deployments, SOC 2 / HIPAA / GDPR compliance logs, or custom DLP rules? Reach out at &lt;a href="mailto:founder@glastor.es"&gt;founder@glastor.es&lt;/a&gt;.*&lt;/p&gt;

</description>
      <category>rust</category>
      <category>ai</category>
      <category>security</category>
      <category>llm</category>
    </item>
  </channel>
</rss>
