Documentation Index Fetch the complete documentation index at: https://docs.praison.ai/llms.txt
Use this file to discover all available pages before exploring further.
Define safety policies to control agent behavior and protect against harmful outputs.
Quick Start
Define Policies
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 '
}
];
Use Preset Policies
import { resolveGuardrailPolicies , GUARDRAIL_PRESETS } from ' praisonai ' ;
// Use preset by name
const resolved = resolveGuardrailPolicies ([ ' strict ' , ' no-pii ' ]);
Policy Actions
Action Behavior blockStop execution and return error warnLog warning and continue logLog event and continue silently allowAllow without any action
GuardrailPolicy Interface
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:
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 strictblockBlock all harmful content moderatewarnWarn on sensitive content permissivelogLog everything, block nothing no-piiblockBlock personal information no-codeblockBlock code execution
Resolve Policies
Convert string presets and policy objects:
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
Content Moderation
Data Protection
Environment-Based
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 );
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 '
}
];
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
GuardrailPolicy Guardrail policy interface
Best Practices
Use strict policies in production
Always use strict and no-pii policies in production environments.
Use warn during development to understand what would be blocked.
Include descriptive messages to help users understand why content was blocked.
Combine multiple policies for comprehensive protection.
Guardrails Full guardrails implementation
LLM Guardrail LLM-based content filtering