| 239 | |
| 240 | #[pyo3(signature = (name: "str", priority: "int", callback: "object") -> "None", text_signature = "(name: str, priority: int, callback: object) -> None")] |
| 241 | fn register_tool_sanitize_request_guardrail( |
| 242 | &self, |
| 243 | name: &str, |
| 244 | priority: i32, |
| 245 | callback: Py<PyAny>, |
| 246 | ) -> PyResult<()> { |
| 247 | let qualified_name = self.qualify_name(name); |
| 248 | register_tool_sanitize_request_guardrail( |
| 249 | &qualified_name, |
| 250 | priority, |
| 251 | wrap_py_tool_fn(callback), |
| 252 | ) |
| 253 | .map_err(to_py_err)?; |
| 254 | |
| 255 | let name_owned = qualified_name; |
| 256 | let mut guard = self.registrations.lock().map_err(|e| { |
| 257 | pyo3::exceptions::PyRuntimeError::new_err(format!("plugin context lock poisoned: {e}")) |
| 258 | })?; |
| 259 | guard.push(PluginRegistration::new( |
| 260 | "plugin", |
| 261 | name_owned.clone(), |
| 262 | Box::new(move || { |
| 263 | deregister_tool_sanitize_request_guardrail(&name_owned) |
| 264 | .map(|_| ()) |
| 265 | .map_err(|e| { |
| 266 | PluginError::RegistrationFailed(format!( |
| 267 | "tool sanitize request guardrail deregistration failed: {e}" |
| 268 | )) |
| 269 | }) |
| 270 | }), |
| 271 | )); |
| 272 | Ok(()) |
| 273 | } |
| 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( |