Soyez opérationnel avec @edwinfom/ai-guard en quelques minutes.

Démarrage rapide

Utilisation sans configuration

import { Guardian } from '@edwinfom/ai-guard';
 
// Zéro config — normalise la réponse du fournisseur, rien n'est bloqué
const guard = new Guardian();
const result = await guard.protect(
  () => openai.chat.completions.create({ model: 'gpt-4o-mini', messages: [...] }),
  userPrompt
);
console.log(result.raw); // texte propre en sortie

Exemple complet avec toutes les protections

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);              // typé par votre schéma Zod
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

Prochaines étapes