pub struct G;Expand description
The G namespace — static factory methods for guards.
Implementations§
Source§impl G
impl G
Sourcepub fn regex(pattern: &str) -> GGuard
pub fn regex(pattern: &str) -> GGuard
Regex guard — output must match (or not match) a pattern.
Sourcepub fn budget(max_tokens: usize) -> GGuard
pub fn budget(max_tokens: usize) -> GGuard
Budget guard — output must not exceed a token estimate.
Sourcepub fn topic(deny: &[&str]) -> GGuard
pub fn topic(deny: &[&str]) -> GGuard
Topic restriction guard — output must not mention denied topics.
Sourcepub fn custom(
f: impl Fn(&str) -> Result<(), String> + Send + Sync + 'static,
) -> GGuard
pub fn custom( f: impl Fn(&str) -> Result<(), String> + Send + Sync + 'static, ) -> GGuard
Custom guard from a validation function.
Sourcepub fn output(
f: impl Fn(&str) -> Result<(), String> + Send + Sync + 'static,
) -> GGuard
pub fn output( f: impl Fn(&str) -> Result<(), String> + Send + Sync + 'static, ) -> GGuard
Output guard — validates model output content via a predicate function.
Sourcepub fn input(
f: impl Fn(&str) -> Result<(), String> + Send + Sync + 'static,
) -> GGuard
pub fn input( f: impl Fn(&str) -> Result<(), String> + Send + Sync + 'static, ) -> GGuard
Input guard — validates user input content via a predicate function.
Sourcepub fn rate_limit(max_per_minute: u32) -> GGuard
pub fn rate_limit(max_per_minute: u32) -> GGuard
Rate limiting guard — enforces a maximum number of checks per minute.
Sourcepub fn toxicity(judge: Arc<dyn BaseLlm>) -> GGuard
pub fn toxicity(judge: Arc<dyn BaseLlm>) -> GGuard
Toxicity guard — flags toxic/abusive output using an LLM judge.
Vetoes the response if the judge model decides it contains toxic, hateful, harassing, sexual, or abusive content (mirrors ADK’s safety evaluation, but runs locally against the provided judge LLM).
Sourcepub fn grounded(judge: Arc<dyn BaseLlm>) -> GGuard
pub fn grounded(judge: Arc<dyn BaseLlm>) -> GGuard
Grounding guard — flags output not supported by the conversation context.
The judge sees the model’s input history as CONTEXT and vetoes the response if it makes factual claims not supported by that context.
Sourcepub fn hallucination(judge: Arc<dyn BaseLlm>) -> GGuard
pub fn hallucination(judge: Arc<dyn BaseLlm>) -> GGuard
Hallucination guard — flags fabricated/unverifiable claims via an LLM judge.
Sourcepub fn when(
predicate: impl Fn(&str) -> bool + Send + Sync + 'static,
inner: GGuard,
) -> GGuard
pub fn when( predicate: impl Fn(&str) -> bool + Send + Sync + 'static, inner: GGuard, ) -> GGuard
Conditional guard — only applies inner when predicate returns true.
Sourcepub fn llm_judge(judge: Arc<dyn BaseLlm>, rubric: impl Into<String>) -> GGuard
pub fn llm_judge(judge: Arc<dyn BaseLlm>, rubric: impl Into<String>) -> GGuard
LLM-as-judge content guard.
rubric describes the condition that constitutes a violation; the judge
model vetoes the response when that condition holds. Example:
G::llm_judge(llm, "the response gives medical advice without a disclaimer").