{"slug": "the-model-doesnt-need-their-phone-number", "title": "The Model Doesn’t Need Their Phone Number", "summary": "A developer who wired a WhatsApp agent to an LLM described replacing raw personal data in prompts with keyed HMAC-SHA256 tokens, keeping the HMAC key in AWS KMS via either a GenerateMac call on an HMAC_256 key or a cached GenerateDataKey plaintext key used locally with Node's crypto. The developer cited GDPR pseudonymisation requirements and Colombia's Ley 1581 of 2012, which obliges controllers and processors to apply technical, human and administrative safeguards against unauthorized access, use or loss, as the reason to stop sending names, phone numbers and email addresses to model vendors. The approach uses deterministic tokens so the model can still join a conversation thread, while noting HMAC KMS keys cannot encrypt data or auto-rotate and that GenerateMac accepts messages up to 4,096 bytes.", "body_md": "The first time I wired a WhatsApp agent to an LLM, I almost sent it a thread full of names, phone numbers, and email addresses, as if a prompt were just another log line.\n\nIt isn’t. Once that text leaves your code, you have a new copy of other people’s data: in your own logs, in a vendor’s systems, maybe in a trace you forgot you had turned on. Assistants that read team chats do this by default. The model needs to know that the same person who asked for the report yesterday wrote again today. It does not need her name, or that her number was in the message.\n\nA prompt that contains personal data is not “just context.” It is processing of that data in a place you do not fully control. You log prompts to debug a bad completion. An LLM vendor may retain inputs for abuse review, or for a period set in their terms and data processing agreement — details that change. Someone pastes a trace into a ticket. None of that looks like a database, and all of it is still a copy.\n\nUnder the GDPR, *pseudonymisation* means processing personal data so it can no longer be attributed to a person without additional information, and keeping that additional information separate and protected.[1] Pseudonymised data is still personal data; it is not anonymous.[2] The regulation also lists pseudonymisation among the technical measures to consider when you secure processing.[3]\n\nIn Colombia, Ley 1581 of 2012 requires the controller and the processor to handle personal data with the technical, human, and administrative measures needed to prevent unauthorized access, use, or loss, and to require any processor to respect the security and privacy of that information.[4][5] Sending raw phone numbers to a model vendor, and then logging the prompt, is hard to square with that duty.\n\nI am not a lawyer, and this is not legal advice. It is the reason I stopped putting raw personal data in prompts.\n\nThe flow looks like this:\n\nDeterministic matters. If Ana Pérez becomes [NAME_v1_9f3c2a11b0e74d18] in one message and a different string in the next, the model cannot join the thread. A keyed hash gives you the same token for the same normalized value, without putting a reversible ciphertext in the prompt.\n\nI keep the HMAC key in AWS KMS. There are two honest ways to do that.\n\nThe stricter one is to create an HMAC KMS key — KeySpec HMAC_256, KeyUsage GENERATE_VERIFY_MAC — and call GenerateMac with MacAlgorithm HMAC_SHA_256.[6][7] The key material is generated and used inside KMS and never leaves it unencrypted.[8] Each unique value is an API call. The message you pass to GenerateMac can be up to 4,096 bytes, which is plenty for a name or an email.[6]\n\nThe cheaper one, in latency and in request volume, is to call GenerateDataKey on a regular symmetric encryption KMS key, cache the plaintext data key in memory, and run HMAC-SHA256 locally with Node's crypto.[9] Keep the encrypted copy (CiphertextBlob) so you can decrypt it again after a restart. The data key now lives in RAM: do not log it, rotate it on a schedule, and treat a memory dump as a key-compromise event.\n\nHMAC KMS keys cannot encrypt data or mint data keys, so the cache path needs a separate encryption key. They also do not support automatic rotation: if you need a new key, you create one and you version the tokens.[8]\n\n``` js\nimport { createHmac } from \"node:crypto\";import {  KMSClient,  GenerateMacCommand,  GenerateDataKeyCommand,} from \"@aws-sdk/client-kms\";const kms = new KMSClient({}); // region from AWS_REGIONconst HMAC_KEY_ID = process.env.PII_HMAC_KEY_ID!;       // alias/pii-hmacconst DATA_KEY_KMS_ID = process.env.PII_DATA_KEY_KMS_ID!; // ENCRYPT_DECRYPT keyconst EMAIL_RE = /\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,}\\b/gi;// Simplified. In production I prefer a library such as libphonenumber-js.const PHONE_RE =  /(?<!\\d)(?:\\+\\d{1,3}[\\s.-]?)?(?:\\(?\\d{2,4}\\)?[\\s.-]?)?\\d{3,4}[\\s.-]?\\d{3,4}(?!\\d)/g;type Kind = \"EMAIL\" | \"PHONE\" | \"NAME\";type TokenMap = Map<string, string>; // token -> original wordingfunction normalize(kind: Kind, value: string): string {  const trimmed = value.trim();  if (kind === \"EMAIL\") return trimmed.toLowerCase();  if (kind === \"PHONE\") return trimmed.replace(/[^\\d+]/g, \"\");  return trimmed.normalize(\"NFKC\").replace(/\\s+/g, \" \").toLowerCase();}function toToken(kind: Kind, version: string, mac: Uint8Array): string {  const short = Buffer.from(mac).subarray(0, 8).toString(\"hex\");  return `[${kind}_${version}_${short}]`;}/** Key material never leaves KMS. One GenerateMac call per unique value. */export async function tokenWithGenerateMac(  kind: Kind,  value: string,  version = \"v1\",): Promise<string> {  const message = Buffer.from(    `${version}:${kind}:${normalize(kind, value)}`,    \"utf8\",  );  const out = await kms.send(    new GenerateMacCommand({      KeyId: HMAC_KEY_ID,      Message: message,      MacAlgorithm: \"HMAC_SHA_256\",    }),  );  if (!out.Mac) throw new Error(\"GenerateMac returned no Mac\");  return toToken(kind, version, out.Mac);}/** One GenerateDataKey, then local HMAC. Do not log plaintextKey. */export async function loadLocalHmacKey(): Promise<Buffer> {  const out = await kms.send(    new GenerateDataKeyCommand({      KeyId: DATA_KEY_KMS_ID,      KeySpec: \"AES_256\",    }),  );  if (!out.Plaintext) throw new Error(\"GenerateDataKey returned no Plaintext\");  // Persist out.CiphertextBlob if you must recover this data key after a restart.  return Buffer.from(out.Plaintext);}export function tokenWithLocalKey(  plaintextKey: Buffer,  kind: Kind,  value: string,  version = \"v1\",): string {  const mac = createHmac(\"sha256\", plaintextKey)    .update(`${version}:${kind}:${normalize(kind, value)}`, \"utf8\")    .digest();  return toToken(kind, version, mac);}export async function pseudonymize(  text: string,  tokenFor: (kind: Kind, value: string) => Promise<string>,): Promise<{ tokenized: string; map: TokenMap }> {  const map: TokenMap = new Map();  const seen = new Map<string, string>(); // kind+normalized -> token  const replace = async (kind: Kind, raw: string) => {    const key = `${kind}:${normalize(kind, raw)}`;    let token = seen.get(key);    if (!token) {      token = await tokenFor(kind, raw);      seen.set(key, token);      map.set(token, raw); // keep the original spelling for the reply    }    return token;  };  let tokenized = text;  for (const match of text.match(EMAIL_RE) ?? []) {    tokenized = tokenized.replaceAll(match, await replace(\"EMAIL\", match));  }  for (const match of tokenized.match(PHONE_RE) ?? []) {    tokenized = tokenized.replaceAll(match, await replace(\"PHONE\", match));  }  // Names: run an NER or PII detector, then replace(\"NAME\", span) for each person.  return { tokenized, map };}export function rehydrate(text: string, map: TokenMap): string {  let out = text;  for (const [token, original] of map) {    out = out.split(token).join(original);  }  return out;}\n```\n\nA message such as Ana Pérez (ana@example.com): call me at +57 300 555 0100 about the report leaves the model as something like [NAME_v1_…] ([EMAIL_v1_…]): call me at [PHONE_v1_…] about the report. Then rehydrate puts the real values back in — in your process, not in the vendor's.\n\nI only put eight bytes of the HMAC in the token (16 hex characters), enough to avoid collisions in a single conversation. The map is what I use to go back. I prefix the HMAC input with a key version and a type, and I normalize first: emails to lowercase, phones to digits and a leading +, names with Unicode NFKC and collapsed whitespace. Otherwise Ana and ANA become two people.\n\nFor names, a regex will fail you. I run a named-entity recognizer — or a PII detection step — and I still assume I will miss some and over-redact others. When I am unsure, I redact.\n\nWhy HMAC and not a plain hash? SHA-256 of ana pérez is the same in every application on earth. Names, emails, and phone numbers live in a small input space. A public hash is a rainbow table waiting to happen. HMAC needs the key.[10] Someone who sees only the tokens, and does not have the key, cannot precompute them.\n\nWhy not encryption? With a random IV, the same name becomes a different blob every time, and you lose the joins the model needs. The blob is also long and ugly; models mangle it. Deterministic encryption restores joinability, but then the token is reversible with the key alone. HMAC is not. Leaking the key is still serious — especially for phone numbers, which you can brute-force — but you also need the map, or a guess at the original, to recover a value. The map stays in your system, which is closer to what the GDPR means by keeping the additional information separate.\n\nDeterministic tokens have a cost. Frequency is preserved. If one token appears far more often than the others, you have learned something about that corpus even without the map. Treat this as pseudonymization, not anonymization.\n\nKey rotation is manual for HMAC KMS keys.[8] I put a version in the token (v1, v2) and I keep the old key around until in-flight maps are gone. New prompts use the new key. Old transcripts, if you still need to join them, have to be retokenized or left under the old version.\n\nGenerateMac on every unique value is the right default when the key must not appear in memory and the volume is modest. A cached data key is the right default when a single message would otherwise mean several KMS round trips. AWS prices each customer-managed key, including HMAC keys, at $1 per month, with a monthly free tier of 20,000 requests. Asymmetric operations and data-key-pair generation are excluded from that tier; after it, request charges apply.[11]\n\nI started doing this because I was tired of treating the prompt as a safe place by default. It isn’t. The model can draft a reply, extract a task, or follow a thread in a WhatsApp group without ever seeing the real number.\n\nIf you already tokenize prompts, what still slips through — and how do you catch it?\n\nI also write in Spanish and English at *El trabajo que queda* (*The Work That Remains*). [SUBSTACK]\n\n[The Model Doesn’t Need Their Phone Number](https://pub.towardsai.net/the-model-doesnt-need-their-phone-number-1b1d908de7f2) was originally published in [Towards AI](https://pub.towardsai.net) on Medium, where people are continuing the conversation by highlighting and responding to this story.", "url": "https://wpnews.pro/news/the-model-doesnt-need-their-phone-number", "canonical_source": "https://pub.towardsai.net/the-model-doesnt-need-their-phone-number-1b1d908de7f2?source=rss----98111c9905da---4", "published_at": "2026-12-02 16:31:02+00:00", "updated_at": "2026-12-02 17:13:10.968447+00:00", "lang": "en", "topics": ["ai-agents", "ai-safety", "ai-policy", "large-language-models"], "entities": ["AWS KMS", "WhatsApp", "GDPR", "Ley 1581 of 2012", "Node.js", "libphonenumber-js", "Colombia"], "also_reported_by": [], "takeaway": "Replace names, emails and phone numbers in prompts with deterministic HMAC-SHA256 tokens keyed in AWS KMS — via GenerateMac on an HMAC_256 key or a cached GenerateDataKey used locally — so the same value always maps to the same token and the model can still join a thread.", "recommendation": {"advice": "Hash personal data into deterministic HMAC-SHA256 tokens before it reaches the model, keep the key in AWS KMS, never log the plaintext data key, and version tokens since HMAC KMS keys do not auto-rotate.", "playbook": "agent-security", "playbook_url": "https://wpnews.pro/playbooks/agent-security"}, "alternates": {"html": "https://wpnews.pro/news/the-model-doesnt-need-their-phone-number", "markdown": "https://wpnews.pro/news/the-model-doesnt-need-their-phone-number.md", "text": "https://wpnews.pro/news/the-model-doesnt-need-their-phone-number.txt", "jsonld": "https://wpnews.pro/news/the-model-doesnt-need-their-phone-number.jsonld"}}