<?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:  PromptAudit</title>
    <description>The latest articles on DEV Community by  PromptAudit (@promptauditsaas).</description>
    <link>https://dev.to/promptauditsaas</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%2F4260512%2Fb2d51416-b7f7-4d63-9ddb-2e3086339981.jpg</url>
      <title>DEV Community:  PromptAudit</title>
      <link>https://dev.to/promptauditsaas</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/promptauditsaas"/>
    <language>en</language>
    <item>
      <title>How to Reversibly Mask API Keys and PII Before Sending Prompts to LLMs (Zero Dependencies)</title>
      <dc:creator> PromptAudit</dc:creator>
      <pubDate>Mon, 23 Nov 2026 12:04:22 +0000</pubDate>
      <link>https://dev.to/promptauditsaas/how-to-reversibly-mask-api-keys-and-pii-before-sending-prompts-to-llms-zero-dependencies-3bp3</link>
      <guid>https://dev.to/promptauditsaas/how-to-reversibly-mask-api-keys-and-pii-before-sending-prompts-to-llms-zero-dependencies-3bp3</guid>
      <description>&lt;p&gt;Every developer building LLM features or autonomous coding agents runs into the same uncomfortable moment:&lt;/p&gt;

&lt;p&gt;A user prompt, a system dump, or a log file contains a sensitive secret — an OpenAI key (&lt;code&gt;sk-proj-...&lt;/code&gt;), an AWS credential (&lt;code&gt;AKIA...&lt;/code&gt;), a private PEM key, or client bank details (IBAN, payment cards). &lt;/p&gt;

&lt;p&gt;If you pass that prompt directly to an external model endpoint, that sensitive data leaves your process boundary and ends up in external inference logs and training pipelines.&lt;/p&gt;

&lt;p&gt;Most teams try one of two extremes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The heavy NLP stack:&lt;/strong&gt; Run a separate Python microservice (like Microsoft Presidio) with spaCy/HuggingFace models in a 500MB+ container. Powerful, but overkill for a simple Node or edge application.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Naive regex replacements:&lt;/strong&gt; A quick &lt;code&gt;.replace()&lt;/code&gt; on strings. This usually breaks order numbers, destroys formatted outputs, and — worst of all — is &lt;strong&gt;irreversible&lt;/strong&gt;. Once you replace the secret with &lt;code&gt;***&lt;/code&gt;, the LLM’s answer has no way to reference the original value back to your user.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here is how to solve this locally in Node.js, the browser, or edge workers with &lt;strong&gt;zero dependencies&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Concept: Reversible In-Memory Shielding
&lt;/h2&gt;

&lt;p&gt;The idea is straightforward:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Before the API call:&lt;/strong&gt; Scan the prompt locally. Replace detected secrets and PII with semantic placeholders (e.g., &lt;code&gt;[API_KEY_1]&lt;/code&gt;, &lt;code&gt;[IBAN_1]&lt;/code&gt;, &lt;code&gt;[NAME_1]&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hold the map in memory:&lt;/strong&gt; The mapping table (&lt;code&gt;[API_KEY_1]&lt;/code&gt; → &lt;code&gt;sk-proj-xyz...&lt;/code&gt;) lives exclusively in your process's local RAM. It never touches the network.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;External inference:&lt;/strong&gt; The model only ever sees the placeholder tokens.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;After the API call:&lt;/strong&gt; When the model replies, restore the original values in the output text using the local map.&lt;/li&gt;
&lt;/ol&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
text
User input:  "Deploy with key sk-proj-AbC123... and refund Mr. Miller, IBAN CH93 0076 2011 6238 5295 7"
                                      │
                         [ Local Shield Engine ]
                                      │
Model sees:  "Deploy with key [API_KEY_1] and refund Mr. [NAME_1], IBAN [IBAN_1]"
                                      │
                         [ External LLM Inference ]
                                      │
Model reply: "Refunding 150 CHF to [IBAN_1] for Mr. [NAME_1] using key [API_KEY_1]."
                                      │
                         [ Local In-Memory Restore ]
                                      │
User gets:   "Refunding 150 CHF to CH93 0076... for Mr. Miller using key sk-proj-AbC123..."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>ai</category>
      <category>typescript</category>
      <category>security</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
