1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct GuardConfig {
8 pub pii: PiiConfig,
10 pub injection: InjectionConfig,
12 pub content_filter: ContentFilterConfig,
14 pub rate_limit: RateLimitConfig,
16 pub audit: AuditConfig,
18}
19
20impl Default for GuardConfig {
21 fn default() -> Self {
22 Self {
23 pii: PiiConfig::default(),
24 injection: InjectionConfig::default(),
25 content_filter: ContentFilterConfig::default(),
26 rate_limit: RateLimitConfig::default(),
27 audit: AuditConfig::default(),
28 }
29 }
30}
31
32impl GuardConfig {
33 pub fn full() -> Self {
35 Self {
36 pii: PiiConfig {
37 enabled: true,
38 ..Default::default()
39 },
40 injection: InjectionConfig {
41 enabled: true,
42 ..Default::default()
43 },
44 content_filter: ContentFilterConfig {
45 enabled: true,
46 ..Default::default()
47 },
48 rate_limit: RateLimitConfig {
49 enabled: true,
50 ..Default::default()
51 },
52 audit: AuditConfig {
53 enabled: true,
54 ..Default::default()
55 },
56 }
57 }
58
59 pub fn minimal() -> Self {
61 Self {
62 pii: PiiConfig {
63 enabled: true,
64 ..Default::default()
65 },
66 injection: InjectionConfig {
67 enabled: false,
68 ..Default::default()
69 },
70 content_filter: ContentFilterConfig {
71 enabled: false,
72 ..Default::default()
73 },
74 rate_limit: RateLimitConfig {
75 enabled: false,
76 ..Default::default()
77 },
78 audit: AuditConfig {
79 enabled: false,
80 ..Default::default()
81 },
82 }
83 }
84}
85
86#[derive(Debug, Clone, Serialize, Deserialize)]
88pub struct PiiConfig {
89 pub enabled: bool,
91 pub detect_ssn: bool,
93 pub detect_credit_card: bool,
95 pub detect_email: bool,
97 pub detect_phone: bool,
99 pub detect_ip: bool,
101 pub detect_api_keys: bool,
103 pub redaction_format: String,
105}
106
107impl Default for PiiConfig {
108 fn default() -> Self {
109 Self {
110 enabled: true,
111 detect_ssn: true,
112 detect_credit_card: true,
113 detect_email: true,
114 detect_phone: true,
115 detect_ip: true,
116 detect_api_keys: true,
117 redaction_format: "[REDACTED:{TYPE}]".to_string(),
118 }
119 }
120}
121
122#[derive(Debug, Clone, Serialize, Deserialize)]
124pub struct InjectionConfig {
125 pub enabled: bool,
127 pub block_on_detection: bool,
129 pub sensitivity: f32,
131 pub custom_patterns: Vec<String>,
133}
134
135impl Default for InjectionConfig {
136 fn default() -> Self {
137 Self {
138 enabled: true,
139 block_on_detection: true,
140 sensitivity: 0.7,
141 custom_patterns: vec![],
142 }
143 }
144}
145
146#[derive(Debug, Clone, Serialize, Deserialize)]
148pub struct ContentFilterConfig {
149 pub enabled: bool,
151 pub api_endpoint: String,
153 pub api_key: Option<String>,
155 pub block_controversial: bool,
157 pub blocked_categories: Vec<String>,
159 pub timeout_ms: u64,
161}
162
163impl Default for ContentFilterConfig {
164 fn default() -> Self {
165 Self {
166 enabled: false, api_endpoint: "https://api.zenlm.ai/v1/guard".to_string(),
168 api_key: None,
169 block_controversial: false,
170 blocked_categories: vec![
171 "Violent".to_string(),
172 "IllegalActs".to_string(),
173 "SexualContent".to_string(),
174 "SelfHarm".to_string(),
175 "Jailbreak".to_string(),
176 ],
177 timeout_ms: 5000,
178 }
179 }
180}
181
182#[derive(Debug, Clone, Serialize, Deserialize)]
184pub struct RateLimitConfig {
185 pub enabled: bool,
187 pub requests_per_minute: u32,
189 pub tokens_per_minute: u32,
191 pub burst_size: u32,
193}
194
195impl Default for RateLimitConfig {
196 fn default() -> Self {
197 Self {
198 enabled: true,
199 requests_per_minute: 60,
200 tokens_per_minute: 100_000,
201 burst_size: 10,
202 }
203 }
204}
205
206#[derive(Debug, Clone, Serialize, Deserialize)]
208pub struct AuditConfig {
209 pub enabled: bool,
211 pub log_content: bool,
213 pub log_stdout: bool,
215 pub log_file: Option<String>,
217}
218
219impl Default for AuditConfig {
220 fn default() -> Self {
221 Self {
222 enabled: true,
223 log_content: false, log_stdout: false,
225 log_file: None,
226 }
227 }
228}