Skip to main content

ExternalGuard

Trait ExternalGuard 

Source
pub trait ExternalGuard: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn cache_key(&self, ctx: &GuardCallContext) -> Option<String>;
    fn eval<'life0, 'life1, 'async_trait>(
        &'life0 self,
        ctx: &'life1 GuardCallContext,
    ) -> Pin<Box<dyn Future<Output = Result<Verdict, ExternalGuardError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
}
Expand description

Trait implemented by guards that call external services.

Keep implementations free of retry / caching / rate-limiting concerns – those are handled by AsyncGuardAdapter. The eval method should describe a single attempt: one HTTP call (or equivalent), one decision.

Required Methods§

Source

fn name(&self) -> &str

Human-readable guard name (e.g. "bedrock-guardrail").

Source

fn cache_key(&self, ctx: &GuardCallContext) -> Option<String>

Return a cache key for this request, or None to skip caching.

Source

fn eval<'life0, 'life1, 'async_trait>( &'life0 self, ctx: &'life1 GuardCallContext, ) -> Pin<Box<dyn Future<Output = Result<Verdict, ExternalGuardError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Evaluate the request against the external service.

Implementors§