Skip to main content

PolicyRule

Defined in the policy module.
Rust AI Agent SDK A policy rule.

Fields

NameTypeDescription
nameStringRule name
descriptionOption<String>Rule description
patternOption<String>Pattern to match (regex)
keywordsVec<String>Keywords to match
actionPolicyActionAction to take
enabledboolWhether the rule is enabled
priorityi32Priority (higher = checked first)
replacementOption<String>Replacement text for redaction

Methods

new

fn new(name: impl Into<String>) -> Self
Create a new rule. Parameters:
NameType
nameimpl Into&lt;String&gt;

description

fn description(mut self, desc: impl Into<String>) -> Self
Set description. Parameters:
NameType
descimpl Into&lt;String&gt;

pattern

fn pattern(mut self, pattern: impl Into<String>) -> Self
Set pattern. Parameters:
NameType
patternimpl Into&lt;String&gt;

keyword

fn keyword(mut self, keyword: impl Into<String>) -> Self
Add keyword. Parameters:
NameType
keywordimpl Into&lt;String&gt;

action

fn action(mut self, action: PolicyAction) -> Self
Set action. Parameters:
NameType
actionPolicyAction

priority

fn priority(mut self, priority: i32) -> Self
Set priority. Parameters:
NameType
priorityi32

replacement

fn replacement(mut self, replacement: impl Into<String>) -> Self
Set replacement. Parameters:
NameType
replacementimpl Into&lt;String&gt;

enable

fn enable(&mut self) -> ()
Enable the rule.

disable

fn disable(&mut self) -> ()
Disable the rule.

matches

fn matches(&self, content: &str) -> bool
Check if content matches this rule. Parameters:
NameType
content&str

apply

fn apply(&self, content: &str) -> PolicyResult
Apply the rule to content. Parameters:
NameType
content&str

Source

View on GitHub

praisonai/src/policy/mod.rs at line 118