Skip to main content

Middleware

Trait Middleware 

Source
pub trait Middleware: Send + Sync {
    // Required methods
    fn name(&self) -> &'static str;
    fn on_result(
        &self,
        tool_id: &str,
        tool_def: &ToolDefinition,
        result: &mut Value,
    );

    // Provided method
    fn on_error(
        &self,
        tool_id: &str,
        tool_def: &ToolDefinition,
        message: &mut String,
        details: &mut Option<Value>,
    ) { ... }
}
Expand description

A result-rewriting hook. Must be deterministic and side-effect-free beyond the result / error mutation + any internal audit sinks the impl owns.

Required Methods§

Source

fn name(&self) -> &'static str

Source

fn on_result( &self, tool_id: &str, tool_def: &ToolDefinition, result: &mut Value, )

Provided Methods§

Source

fn on_error( &self, tool_id: &str, tool_def: &ToolDefinition, message: &mut String, details: &mut Option<Value>, )

SP-observability-completeness-v1 Axis A. Egress redaction for the FAILURE wire shape Response::Error { message, details } — the InvalidArgs / InternalError dispatch exits. Default is a no-op, preserving pre-SP behaviour for middleware that only rewrite success results. Security-sensitive middleware (PHI / PII redaction) MUST override this — a tool’s failure text reaches the LLM verbatim and may carry PHI (an arg echo, a panic message naming a patient). details is the optional structured error payload; redact both.

Note: the ExecutionFailed exit returns a ToolResultResponse whose result is a Value and so runs through on_result, not this hook. This hook is only for the bare-message Response::Error.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§