Composes a tool from securer::securer_tool() with guardrails from
secureguard. The returned object is itself a
securer::securer_tool() (same schema, same IPC contract) whose
closure runs each invocation through the supplied input guardrails,
executes the underlying tool, then runs the result through the output
guardrails.
Arguments
- tool
A
securer_toolobject (typically from one of thetool_*()factories in this package, but anysecurer_toolworks).- input_guards
A list of
secureguardinput guardrails (type"input"or"code"). Each receives the stringified tool args and must pass for the call to proceed.- output_guards
A list of
secureguardoutput guardrails (type"output"). Each receives the tool's return value (coerced to text viasecureguard::output_to_text) and must pass for the result to be returned.
Details
Guardrail failures are translated into errors raised from the tool
closure; inside a securer session these surface as tool-call errors
and are returned to the LLM via ellmer's ContentToolResult(error =)
shape.
Guardrails are applied lazily: if secureguard is not installed,
calling guarded_tool() errors with a clear installation hint rather
than silently skipping enforcement.
Examples
if (FALSE) { # \dontrun{
calc <- tool_calculator()
injection <- secureguard::guard_prompt_injection()
secrets <- secureguard::guard_output_secrets(action = "block")
guarded <- guarded_tool(
calc,
input_guards = list(injection),
output_guards = list(secrets)
)
} # }