Protect LLM prompts
A model rarely needs to know who; it needs to know that. Replace personal data with tokens before the prompt leaves, and put the values back in the answer:
"Write to ana@example.com" → model sees "Write to {{EMAIL_1}}" → "Done: {{EMAIL_1}} notified"
→ "Done: ana@example.com notified"
The mapping stays in your process (or in a vault you choose); the provider never sees it.
With the Vercel AI SDK
npm install anonyma anonyma-vercel-ai ai
import { generateText } from "ai";
import { withAnonyma } from "anonyma-vercel-ai";
const { text } = await generateText({
model: withAnonyma("openai/gpt-5"),
prompt: "Draft a reply to ana@example.com about order 1182.",
});
// The model saw {{EMAIL_1}}; `text` has the address back.
Streaming works too: a token split across chunks is held back until it is complete. See Vercel AI SDK.
With any client
import { createLlmGuard } from "anonyma/ai";
const guard = createLlmGuard({ session: { format: "brace" } }); // once, at start-up
const exchange = guard.begin(); // per conversation
const { messages } = exchange.sanitizeMessages([
{ role: "user", content: "Email ana@example.com" },
]);
const answer = await callYourModel(messages); // sees {{EMAIL_1}}
exchange.restoreText(answer).text; // the original address is back
Across requests
A conversation that spans requests needs the mapping to outlive the request. Either keep the guard's snapshot on your side and resume from it:
const exchange = guard.begin(loadSnapshot(conversationId)); // undefined on the first turn
// … sanitize, call the model, restore …
saveSnapshot(conversationId, exchange.snapshot()); // holds the original values: keep it private
or put the tokens in a store. Any object with store() and retrieve() is an AnonymaVault:
import { compilePipeline } from "anonyma/engine";
import { createVaultTokenizer, restore } from "anonyma/vault";
const vault = redisVault(conversationId); // your implementation: store(key, value), retrieve(key)
const pipeline = compilePipeline(
{ defaultStrategy: { strategy: "tokenize" } },
{ tokenization: createVaultTokenizer({ vault }) },
);
const { text: prompt } = await pipeline.transformAsync(userMessage); // "… {{EMAIL_1}} …"
const { text } = await restore(await callYourModel(prompt), vault);
Keep restoration scoped to the conversation that issued the tokens: a token from one conversation must never bring back a value from another.
For MCP tools
Put any MCP server behind anonyma-mcp-proxy: tool results reach the model as
tokens, and tool arguments reach the server as real values.