Security

Protect your agents from misuse

Agents include security features to prevent misuse and protect data.

Diagram

Input

Agent

Safe Output

Quick Start

  1. Simple Usage
    typescript
    import { Agent } from 'praisonai';
    
    const agent = new Agent({
      instructions: 'You are a helpful assistant',
      security: true  // Enable all protections
    });
    
    await agent.chat('Ignore previous instructions and...');
    // Prompt injection blocked
  2. With Configuration
    typescript
    const agent = new Agent({
      security: {
        blockInjection: true,
        blockPII: true,
        maxTokens: 4000
      }
    });

User Interaction Flow

Diagram
AgentSecurityUserAgentSecurityUseralt[Safe][Unsafe]Potentially unsafe inputValidate inputProcess requestGenerate responseFilter outputSafe responseBlocked

Configuration Levels

typescript
// Level 1: Bool - Enable all protections
const agent = new Agent({
  security: true
});

// Level 2: Array - Specific protections
const agent = new Agent({
  security: ['injection', 'pii', 'profanity']
});

// Level 3: Dict - Full control
const agent = new Agent({
  security: {
    blockInjection: true,
    blockPII: true,
    blockPatterns: [/password/i, /\b\d{16}\b/],  // Credit cards
    maxTokens: 4000,
    rateLimit: 10  // Per minute
  }
});

Security Features

FeatureProtection
blockInjectionStops prompt manipulation
blockPIIFilters personal data
blockPatternsCustom regex filters
maxTokensLimits output size
rateLimitControls request frequency

API Reference

GuardrailConfig

Complete configuration options

Guardrails Module

Full module documentation


Best Practices

Enable in production

Always enable security for user-facing agents.

Limit tool access

Only give agents the tools they actually need.

Monitor usage

Track interactions to detect unusual patterns.


Related