| 379 | |
| 380 | #[pyo3(signature = (name: "str", priority: "int", callback: "object") -> "None", text_signature = "(name: str, priority: int, callback: object) -> None")] |
| 381 | fn register_llm_sanitize_response_guardrail( |
| 382 | &self, |
| 383 | name: &str, |
| 384 | priority: i32, |
| 385 | callback: Py<PyAny>, |
| 386 | ) -> PyResult<()> { |
| 387 | let qualified_name = self.qualify_name(name); |
| 388 | register_llm_sanitize_response_guardrail( |
| 389 | &qualified_name, |
| 390 | priority, |
| 391 | wrap_py_llm_sanitize_response_fn(callback), |
| 392 | ) |
| 393 | .map_err(to_py_err)?; |
| 394 | |
| 395 | let name_owned = qualified_name; |
| 396 | let mut guard = self.registrations.lock().map_err(|e| { |
| 397 | pyo3::exceptions::PyRuntimeError::new_err(format!("plugin context lock poisoned: {e}")) |
| 398 | })?; |
| 399 | guard.push(PluginRegistration::new( |
| 400 | "plugin", |
| 401 | name_owned.clone(), |
| 402 | Box::new(move || { |
| 403 | deregister_llm_sanitize_response_guardrail(&name_owned) |
| 404 | .map(|_| ()) |
| 405 | .map_err(|e| { |
| 406 | PluginError::RegistrationFailed(format!( |
| 407 | "llm sanitize response guardrail deregistration failed: {e}" |
| 408 | )) |
| 409 | }) |
| 410 | }), |
| 411 | )); |
| 412 | Ok(()) |
| 413 | } |
| 414 | |
| 415 | #[pyo3(signature = (name: "str", priority: "int", callback: "object") -> "None", text_signature = "(name: str, priority: int, callback: object) -> None")] |
| 416 | fn register_llm_conditional_execution_guardrail( |