Cookbook
Raw Claude (no framework)
Screen a prompt before a Claude call, without the Vercel AI SDK.
If you're calling the Anthropic client directly — no Vercel AI SDK — screen the prompt yourself before the call. If Tawa blocks or leans toward blocking, the request is rejected without ever reaching Claude.
import Anthropic from "@anthropic-ai/sdk";
import { TawaGuard } from "@tawaguard/sdk";
const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
const tawa = await TawaGuard.create(process.env.TAWA_API_KEY!);
const BLOCKED_ACTIONS = new Set(["block", "hard_block", "soft_block"]);
async function chat(userMessage: string) {
const scan = await tawa.analyze(userMessage);
if (BLOCKED_ACTIONS.has(scan.action) || scan.suggestion === "block") {
throw new Error("Message blocked by content policy.");
}
return anthropic.messages.create({
model: "claude-opus-5",
max_tokens: 1024,
messages: [{ role: "user", content: userMessage }],
});
}On Next.js with the Vercel AI SDK? The Vercel AI SDK
integration wraps this
pattern for you — no manual check needed at every call site. It works with
any AI SDK provider, including @ai-sdk/anthropic, not just OpenAI.