🛡️ Security & AIDefence
/programmatic-usage/security--aidefence
typescript
import { isSafe, checkThreats, createAIDefence } from '@claude-flow/aidefence';
// Quick safety check
if (!isSafe(userInput)) {
throw new Error('Potentially malicious input detected');
}
// Detailed threat analysis
const result = checkThreats(userInput);
if (!result.safe) {
console.log('Threats:', result.threats);
console.log('PII found:', result.piiFound);
}
// With learning enabled
const aidefence = createAIDefence({ enableLearning: true });
const analysis = await aidefence.detect(userInput);
// Provide feedback for learning
await aidefence.learnFromDetection(userInput, analysis, {
wasAccurate: true,
userVerdict: 'Confirmed threat'
});