Class AbstractToolGuardrailExecutor<C extends GuardrailsConfig, P extends GuardrailRequest<P>, R extends GuardrailResult<R>, G extends Guardrail<P,R>, E extends GuardrailExecutedEvent<P,R,G>, F extends GuardrailResult.Failure>

java.lang.Object
dev.langchain4j.guardrail.AbstractGuardrailExecutor<C,P,R,G,E,F>
dev.langchain4j.guardrail.AbstractToolGuardrailExecutor<C,P,R,G,E,F>
Type Parameters:
C - The type of GuardrailsConfig to use for configuration
P - The type of GuardrailRequest to validate
R - The type of GuardrailResult to return
G - The type of Guardrails being executed
E - The type of GuardrailExecutedEvent to be fired
F - The type of GuardrailResult.Failure to return
All Implemented Interfaces:
GuardrailExecutor<C,P,R,G,E>
Direct Known Subclasses:
ToolInputGuardrailExecutor, ToolOutputGuardrailExecutor

public abstract sealed class AbstractToolGuardrailExecutor<C extends GuardrailsConfig, P extends GuardrailRequest<P>, R extends GuardrailResult<R>, G extends Guardrail<P,R>, E extends GuardrailExecutedEvent<P,R,G>, F extends GuardrailResult.Failure> extends AbstractGuardrailExecutor<C,P,R,G,E,F> permits ToolInputGuardrailExecutor, ToolOutputGuardrailExecutor
Base class of the GuardrailExecutors of tool guardrails, which share the same semantics:
  • the guardrails run once, with no retry or reprompt;
  • a non-fatal failure does not stop the chain and is returned, not thrown, so that the caller can turn it into an error tool result;
  • a fatal failure stops the chain and is thrown (async: fails the future) as the GuardrailException created by AbstractGuardrailExecutor.createGuardrailException(String, Throwable), which names the tool in its message and carries the tool call it stopped (toolExecutionRequest()). This covers a fatal result, a guardrail that throws, and, for the input guardrails, a rewrite to something that is not a JSON object.
Since:
1.25.0