Flow 08 / 14PackagesVercel AI SDK10 tests
Vercel AI SDK — veilgate-ai-sdk
Vercel AI SDK middleware that redacts PII and secrets from prompts. Redacts in wrapGenerate and is fail-closed on streaming so a stream can never bypass redaction.
peer · ai v7+
veilgate-ai-sdk is a LanguageModelV2Middleware for the Vercel AI SDK.
10 tests.
terminal
npm install veilgate-ai-sdkPeer dependency: ai (v7+).
createRedactionMiddleware(options?)
model.ts
import { wrapLanguageModel } from "ai";
import { openai } from "@ai-sdk/openai";
import { createRedactionMiddleware } from "veilgate-ai-sdk";
import { PRESETS } from "veilgate-policy";
const model = wrapLanguageModel({
model: openai("gpt-4o"),
middleware: createRedactionMiddleware({ policy: PRESETS["gdpr-strict"] }),
});
// Prompts are redacted before they reach the provider.
await generateText({ model, prompt: "My name is Alice Johnson." });The middleware redacts the prompt in wrapGenerate before the request reaches the provider.
Streaming is fail-closed
wrapStream throws RedactionBlockedError rather than let streamText send an unredacted
prompt. Streaming redaction-plus-re-hydration of a live token stream is not yet implemented, so
the middleware refuses the stream instead of leaking. Use generateText for redacted calls
today, or catch the error and fall back.
redactPrompt(prompt, options?)
The lower-level helper the middleware uses — redact an AI SDK prompt directly:
prompt.ts
import { redactPrompt } from "veilgate-ai-sdk";
const { prompt, vault, blocked } = await redactPrompt(originalPrompt, { policy });Exports
| Export | Purpose |
|---|---|
createRedactionMiddleware |
The LanguageModelV2Middleware factory |
RedactionBlockedError |
Thrown on a BLOCK, and on any stream call |
redactPrompt |
Redact an AI SDK prompt directly |