1use adk_core::Content;
2use async_trait::async_trait;
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7pub enum Severity {
8 Low,
9 Medium,
10 High,
11 Critical,
12}
13
14#[derive(Debug, Clone)]
16pub enum GuardrailResult {
17 Pass,
19 Fail { reason: String, severity: Severity },
21 Transform { new_content: Content, reason: String },
23}
24
25impl GuardrailResult {
26 pub fn pass() -> Self {
27 Self::Pass
28 }
29
30 pub fn fail(reason: impl Into<String>, severity: Severity) -> Self {
31 Self::Fail { reason: reason.into(), severity }
32 }
33
34 pub fn transform(new_content: Content, reason: impl Into<String>) -> Self {
35 Self::Transform { new_content, reason: reason.into() }
36 }
37
38 pub fn is_pass(&self) -> bool {
39 matches!(self, Self::Pass)
40 }
41
42 pub fn is_fail(&self) -> bool {
43 matches!(self, Self::Fail { .. })
44 }
45}
46
47#[async_trait]
49pub trait Guardrail: Send + Sync {
50 fn name(&self) -> &str;
52
53 async fn validate(&self, content: &Content) -> GuardrailResult;
55
56 fn run_parallel(&self) -> bool {
58 true
59 }
60
61 fn fail_fast(&self) -> bool {
63 true
64 }
65}