| 274 | |
| 275 | #[pyo3(signature = (name: "str", priority: "int", callback: "object") -> "None", text_signature = "(name: str, priority: int, callback: object) -> None")] |
| 276 | fn register_tool_sanitize_response_guardrail( |
| 277 | &self, |
| 278 | name: &str, |
| 279 | priority: i32, |
| 280 | callback: Py<PyAny>, |
| 281 | ) -> PyResult<()> { |
| 282 | let qualified_name = self.qualify_name(name); |
| 283 | register_tool_sanitize_response_guardrail( |
| 284 | &qualified_name, |
| 285 | priority, |
| 286 | wrap_py_tool_fn(callback), |
| 287 | ) |
| 288 | .map_err(to_py_err)?; |
| 289 | |
| 290 | let name_owned = qualified_name; |
| 291 | let mut guard = self.registrations.lock().map_err(|e| { |
| 292 | pyo3::exceptions::PyRuntimeError::new_err(format!("plugin context lock poisoned: {e}")) |
| 293 | })?; |
| 294 | guard.push(PluginRegistration::new( |
| 295 | "plugin", |
| 296 | name_owned.clone(), |
| 297 | Box::new(move || { |
| 298 | deregister_tool_sanitize_response_guardrail(&name_owned) |
| 299 | .map(|_| ()) |
| 300 | .map_err(|e| { |
| 301 | PluginError::RegistrationFailed(format!( |
| 302 | "tool sanitize response guardrail deregistration failed: {e}" |
| 303 | )) |
| 304 | }) |
| 305 | }), |
| 306 | )); |
| 307 | Ok(()) |
| 308 | } |
| 309 | |
| 310 | #[pyo3(signature = (name: "str", priority: "int", callback: "object") -> "None", text_signature = "(name: str, priority: int, callback: object) -> None")] |
| 311 | fn register_tool_conditional_execution_guardrail( |