Skip to main content

Guardrail

Trait Guardrail 

Source
pub trait Guardrail: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn check_request(
        &self,
        request: &ChatRequest,
    ) -> Result<(), GuardrailViolation>;
    fn check_response(
        &self,
        request: &ChatRequest,
        response: &ChatResponse,
    ) -> Result<(), GuardrailViolation>;
}
Expand description

Trait for synchronous pre/post request validation.

Guardrails run fast, in-memory checks. They must be Send + Sync to work with async providers, but the checks themselves are synchronous.

Required Methods§

Source

fn name(&self) -> &str

Human-readable name for this guardrail

Source

fn check_request(&self, request: &ChatRequest) -> Result<(), GuardrailViolation>

Validate a request before it reaches the provider.

Return Ok(()) to allow the request, or Err(GuardrailViolation) to reject it.

Source

fn check_response( &self, request: &ChatRequest, response: &ChatResponse, ) -> Result<(), GuardrailViolation>

Validate a response after it comes back from the provider.

Return Ok(()) to allow the response, or Err(GuardrailViolation) to reject it.

Implementors§