use adk_core::Content;
use async_trait::async_trait;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum Severity {
Low,
Medium,
High,
Critical,
}
#[derive(Debug, Clone)]
pub enum GuardrailResult {
Pass,
Fail { reason: String, severity: Severity },
Transform { new_content: Content, reason: String },
}
impl GuardrailResult {
pub fn pass() -> Self {
Self::Pass
}
pub fn fail(reason: impl Into<String>, severity: Severity) -> Self {
Self::Fail { reason: reason.into(), severity }
}
pub fn transform(new_content: Content, reason: impl Into<String>) -> Self {
Self::Transform { new_content, reason: reason.into() }
}
pub fn is_pass(&self) -> bool {
matches!(self, Self::Pass)
}
pub fn is_fail(&self) -> bool {
matches!(self, Self::Fail { .. })
}
}
#[async_trait]
pub trait Guardrail: Send + Sync {
fn name(&self) -> &str;
async fn validate(&self, content: &Content) -> GuardrailResult;
fn run_parallel(&self) -> bool {
true
}
fn fail_fast(&self) -> bool {
true
}
}