> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Guardrail Policies

> Define and resolve guardrail policies for agent safety

Define safety policies to control agent behavior and protect against harmful outputs.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    subgraph "Guardrail Flow"
        A[📥 Input] --> B{🛡️ Policy}
        B -->|Allow| C[✅ Process]
        B -->|Block| D[🚫 Reject]
        B -->|Warn| E[⚠️ Log & Process]
    end
    
    classDef input fill:#6366F1,stroke:#7C90A0,color:#fff
    classDef policy fill:#F59E0B,stroke:#7C90A0,color:#fff
    classDef allow fill:#10B981,stroke:#7C90A0,color:#fff
    classDef block fill:#8B0000,stroke:#7C90A0,color:#fff
    classDef warn fill:#189AB4,stroke:#7C90A0,color:#fff
    
    class A input
    class B policy
    class C allow
    class D block
    class E warn
    classDef agent fill:#8B0000,color:#fff
    classDef tool fill:#189AB4,color:#fff
```

## Quick Start

**1. Define Policies**

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import { GuardrailPolicy, resolveGuardrailPolicies } from 'praisonai';

const policies: GuardrailPolicy[] = [
  {
    name: 'no-pii',
    action: 'block',
    message: 'PII detected in output'
  },
  {
    name: 'content-filter',
    action: 'warn',
    message: 'Potentially sensitive content'
  }
];
```

**2. Use Preset Policies**

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import { resolveGuardrailPolicies, GUARDRAIL_PRESETS } from 'praisonai';

// Use preset by name
const resolved = resolveGuardrailPolicies(['strict', 'no-pii']);
```

***

## Policy Actions

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph TB
    subgraph "Choose Your Action"
        A{What should happen?}
        A -->|Stop execution| B[🚫 block]
        A -->|Log and continue| C[⚠️ warn]
        A -->|Just log| D[📝 log]
        A -->|Do nothing| E[✅ allow]
    end
    
    classDef question fill:#6366F1,stroke:#7C90A0,color:#fff
    classDef block fill:#8B0000,stroke:#7C90A0,color:#fff
    classDef warn fill:#F59E0B,stroke:#7C90A0,color:#fff
    classDef log fill:#189AB4,stroke:#7C90A0,color:#fff
    classDef allow fill:#10B981,stroke:#7C90A0,color:#fff
    
    class A question
    class B block
    class C warn
    class D log
    class E allow
```

| Action | Behavior |
| - | - |
| `block` | Stop execution and return error |
| `warn` | Log warning and continue |
| `log` | Log event and continue silently |
| `allow` | Allow without any action |

***

## GuardrailPolicy Interface

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
interface GuardrailPolicy {
  name: string;                    // Policy name
  action: 'block' | 'warn' | 'log' | 'allow';
  conditions?: Record<string, any>; // Optional conditions
  message?: string;                // Message to show/log
}
```

***

## Preset Policies

Use built-in presets for common scenarios:

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import { GUARDRAIL_PRESETS, resolveGuardrailPolicies } from 'praisonai';

// Available presets
GUARDRAIL_PRESETS.strict      // Block harmful content
GUARDRAIL_PRESETS.moderate    // Warn on sensitive content
GUARDRAIL_PRESETS.permissive  // Log only, allow all
GUARDRAIL_PRESETS['no-pii']   // Block PII
GUARDRAIL_PRESETS['no-code']  // Block code execution

// Resolve by name
const policies = resolveGuardrailPolicies(['strict', 'no-pii']);
```

### Preset Definitions

| Preset | Action | Description |
| - | - | - |
| `strict` | `block` | Block all harmful content |
| `moderate` | `warn` | Warn on sensitive content |
| `permissive` | `log` | Log everything, block nothing |
| `no-pii` | `block` | Block personal information |
| `no-code` | `block` | Block code execution |

***

## Resolve Policies

Convert string presets and policy objects:

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import { resolveGuardrailPolicies, GuardrailPolicy } from 'praisonai';

// Mix of presets and custom policies
const policies = resolveGuardrailPolicies([
  'strict',                           // Preset name
  'no-pii',                           // Preset name
  {                                   // Custom policy
    name: 'custom-filter',
    action: 'warn',
    message: 'Custom warning'
  }
]);

// Returns array of GuardrailPolicy objects
console.log(policies);
```

***

## Common Patterns

> [tab] Content Moderation
>
> ```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
> import { resolveGuardrailPolicies, GuardrailPolicy } from 'praisonai';
>
> const moderationPolicies: GuardrailPolicy[] = [
>   {
>     name: 'profanity-filter',
>     action: 'block',
>     message: 'Profanity detected'
>   },
>   {
>     name: 'hate-speech',
>     action: 'block',
>     message: 'Hate speech detected'
>   },
>   {
>     name: 'spam-detection',
>     action: 'warn',
>     message: 'Potential spam detected'
>   }
> ];
>
> const resolved = resolveGuardrailPolicies(moderationPolicies);
> ```

> [tab] Data Protection
>
> ```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
> import { GuardrailPolicy } from 'praisonai';
>
> const dataProtectionPolicies: GuardrailPolicy[] = [
>   {
>     name: 'pii-detection',
>     action: 'block',
>     conditions: {
>       patterns: ['ssn', 'credit-card', 'phone']
>     },
>     message: 'Personal information detected'
>   },
>   {
>     name: 'api-key-leak',
>     action: 'block',
>     conditions: {
>       patterns: ['sk-', 'api_key', 'secret']
>     },
>     message: 'API key detected in output'
>   }
> ];
> ```

> [tab] Environment-Based
>
> ```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
> import { resolveGuardrailPolicies } from 'praisonai';
>
> function getPolicies() {
>   if (process.env.NODE_ENV === 'production') {
>     return resolveGuardrailPolicies(['strict', 'no-pii']);
>   } else if (process.env.NODE_ENV === 'staging') {
>     return resolveGuardrailPolicies(['moderate']);
>   } else {
>     return resolveGuardrailPolicies(['permissive']);
>   }
> }
> ```

***

## API Reference

> [card] [GuardrailPolicy](https://praison.ai/docs/sdk/reference/typescript/classes/GuardrailPolicy.md)
>
> Guardrail policy interface

***

## Best Practices

> [accordion] Use strict policies in production
>
> Always use `strict` and `no-pii` policies in production environments.

> [accordion] Log before blocking
>
> Use `warn` during development to understand what would be blocked.

> [accordion] Provide clear messages
>
> Include descriptive messages to help users understand why content was blocked.

> [accordion] Layer policies
>
> Combine multiple policies for comprehensive protection.

***

## Related

> [card] [Guardrails](https://praison.ai/docs/js/guardrails.md)
>
> Full guardrails implementation

> [card] [LLM Guardrail](https://praison.ai/docs/js/llm-guardrail.md)
>
> LLM-based content filtering


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.