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§
Sourcefn check_request(&self, request: &ChatRequest) -> Result<(), GuardrailViolation>
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.
Sourcefn check_response(
&self,
request: &ChatRequest,
response: &ChatResponse,
) -> Result<(), GuardrailViolation>
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.