pub struct G;Expand description
The G namespace — static factory methods for guards.
Implementations§
Source§impl G
impl G
Sourcepub fn length(min: usize, max: usize) -> GuardRule
pub fn length(min: usize, max: usize) -> GuardRule
Length guard — output must be within bounds.
Sourcepub fn regex(pattern: &str) -> GuardRule
pub fn regex(pattern: &str) -> GuardRule
Regex guard — output must match (or not match) a pattern.
Sourcepub fn budget(max_tokens: usize) -> GuardRule
pub fn budget(max_tokens: usize) -> GuardRule
Budget guard — output must not exceed a token estimate.
Sourcepub fn topic(deny: &[&str]) -> GuardRule
pub fn topic(deny: &[&str]) -> GuardRule
Topic restriction guard — output must not mention denied topics.
Sourcepub fn custom(
f: impl Fn(&str) -> Result<(), String> + Send + Sync + 'static,
) -> GuardRule
pub fn custom( f: impl Fn(&str) -> Result<(), String> + Send + Sync + 'static, ) -> GuardRule
Custom guard from a validation function.
Sourcepub fn toxicity(judge: Arc<dyn BaseLlm>) -> GuardRule
pub fn toxicity(judge: Arc<dyn BaseLlm>) -> GuardRule
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>) -> GuardRule
pub fn grounded(judge: Arc<dyn BaseLlm>) -> GuardRule
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>) -> GuardRule
pub fn hallucination(judge: Arc<dyn BaseLlm>) -> GuardRule
Hallucination guard — flags fabricated/unverifiable claims via an LLM judge.
Sourcepub fn when(
predicate: impl Fn(&str) -> bool + Send + Sync + 'static,
inner: GuardRule,
) -> GuardRule
pub fn when( predicate: impl Fn(&str) -> bool + Send + Sync + 'static, inner: GuardRule, ) -> GuardRule
Conditional guard — only applies inner when predicate returns true.
Sourcepub fn llm_judge(
judge: Arc<dyn BaseLlm>,
rubric: impl Into<String>,
) -> GuardRule
pub fn llm_judge( judge: Arc<dyn BaseLlm>, rubric: impl Into<String>, ) -> GuardRule
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").
Auto Trait Implementations§
impl Freeze for G
impl RefUnwindSafe for G
impl Send for G
impl Sync for G
impl Unpin for G
impl UnwindSafe for G
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].