Get up and running with @edwinfom/ai-guard in minutes.
import { Guardian } from '@edwinfom/ai-guard';
// Zero config — normalizes provider response, nothing blocked
const guard = new Guardian();
const result = await guard.protect(
() => openai.chat.completions.create({ model: 'gpt-4o-mini', messages: [...] }),
userPrompt
);
console.log(result.raw); // clean text output
import { Guardian } from '@edwinfom/ai-guard';
import { z } from 'zod';
const guard = new Guardian({
pii: { onInput: true, onOutput: true },
schema: { validator: z.object({ city: z.string(), temp: z.number() }), repair: 'retry' },
injection: { enabled: true, sensitivity: 'medium' },
content: { enabled: true, sensitivity: 'medium' },
canary: { enabled: true },
hallucination:{ sources: [ragDocument1, ragDocument2] },
budget: { maxTokens: 2000, maxCostUSD: 0.05, model: 'gpt-4o-mini' },
rateLimit: { maxRequests: 10, windowMs: 60_000, keyFn: (p) => getUserId(p) },
onAudit: (entry) => logger.info(entry),
});
const result = await guard.protect(
(safePrompt) => openai.chat.completions.create({
model: 'gpt-4o-mini',
messages: [{ role: 'user', content: safePrompt }]
}),
userPrompt
);
console.log(result.data); // typed by your Zod schema
console.log(result.meta.budget); // { totalTokens: 312, estimatedCostUSD: 0.000047 }
console.log(result.meta.piiRedacted); // [{ type: 'email', value: 'user@...', ... }]
console.log(result.meta.canaryLeaked); // false