pub struct ConditionalGuardrail { /* private fields */ }Expand description
Predicate-gated guardrail — only runs the inner guardrail when the
predicate returns true for the tool name.
Use for patterns like “apply this guardrail only to MCP tools” or “only check bash tool calls”.
The predicate receives the tool name for pre_tool/post_tool hooks.
For pre_llm/post_llm hooks (no tool name), the inner guardrail
always runs.
Implementations§
Trait Implementations§
Source§impl Guardrail for ConditionalGuardrail
impl Guardrail for ConditionalGuardrail
Source§fn name(&self) -> &str
fn name(&self) -> &str
Human-readable name for this guardrail, used in events and audit.
Override to attribute which guardrail fired in logs.
Source§fn pre_llm(
&self,
request: &mut CompletionRequest,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_>>
fn pre_llm( &self, request: &mut CompletionRequest, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_>>
Called before each LLM call. Can mutate the request (e.g., inject safety
instructions, redact content).
Err aborts the run.Source§fn post_llm(
&self,
response: &mut CompletionResponse,
) -> Pin<Box<dyn Future<Output = Result<GuardAction, Error>> + Send + '_>>
fn post_llm( &self, response: &mut CompletionResponse, ) -> Pin<Box<dyn Future<Output = Result<GuardAction, Error>> + Send + '_>>
Called after each LLM response. Can inspect and mutate the response
(e.g. redact PII in
ContentBlock::Text blocks before it reaches the
caller, audit log, or downstream tools). Read moreSource§fn pre_tool(
&self,
call: &ToolCall,
) -> Pin<Box<dyn Future<Output = Result<GuardAction, Error>> + Send + '_>>
fn pre_tool( &self, call: &ToolCall, ) -> Pin<Box<dyn Future<Output = Result<GuardAction, Error>> + Send + '_>>
Called before each tool execution. Can deny individual tool calls.
Deny returns a ToolResult::error for that call. Err aborts the run.Source§fn post_tool(
&self,
call: &ToolCall,
output: &mut ToolOutput,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_>>
fn post_tool( &self, call: &ToolCall, output: &mut ToolOutput, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_>>
Called after each tool execution (after truncation). Can mutate the
output (e.g., redact sensitive data).
Err converts to a tool error
(consistent with tool execution errors — the agent loop continues).Auto Trait Implementations§
impl Freeze for ConditionalGuardrail
impl !RefUnwindSafe for ConditionalGuardrail
impl Send for ConditionalGuardrail
impl Sync for ConditionalGuardrail
impl Unpin for ConditionalGuardrail
impl UnsafeUnpin for ConditionalGuardrail
impl !UnwindSafe for ConditionalGuardrail
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
Mutably borrows from an owned value. Read more