Class ToolOutputGuardrailExecutor
java.lang.Object
dev.langchain4j.guardrail.AbstractGuardrailExecutor<ToolOutputGuardrailsConfig, ToolOutputGuardrailRequest, ToolOutputGuardrailResult, ToolOutputGuardrail, ToolOutputGuardrailExecutedEvent, ToolOutputGuardrailResult.Failure>
dev.langchain4j.guardrail.AbstractToolGuardrailExecutor<ToolOutputGuardrailsConfig, ToolOutputGuardrailRequest, ToolOutputGuardrailResult, ToolOutputGuardrail, ToolOutputGuardrailExecutedEvent, ToolOutputGuardrailResult.Failure>
dev.langchain4j.guardrail.ToolOutputGuardrailExecutor
- All Implemented Interfaces:
GuardrailExecutor<ToolOutputGuardrailsConfig, ToolOutputGuardrailRequest, ToolOutputGuardrailResult, ToolOutputGuardrail, ToolOutputGuardrailExecutedEvent>
@Experimental
public non-sealed class ToolOutputGuardrailExecutor
extends AbstractToolGuardrailExecutor<ToolOutputGuardrailsConfig, ToolOutputGuardrailRequest, ToolOutputGuardrailResult, ToolOutputGuardrail, ToolOutputGuardrailExecutedEvent, ToolOutputGuardrailResult.Failure>
The
GuardrailExecutor for ToolOutputGuardrails.
It runs the guardrails once, with no retry or reprompt. A non-fatal failure does not stop the chain, and
execute(...) returns it instead of throwing, so the caller can turn it into an
error tool result. A fatal failure stops the chain and throws a ToolOutputGuardrailException.
- Since:
- 1.25.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder class for constructing instances ofToolOutputGuardrailExecutor.Nested classes/interfaces inherited from class AbstractGuardrailExecutor
AbstractGuardrailExecutor.GuardrailExecutorBuilder<C,R, P, G, E, B> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedToolOutputGuardrailExecutor(ToolOutputGuardrailsConfig config, List<ToolOutputGuardrail> guardrails) -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Creates and returns a new builder forToolOutputGuardrailExecutor: the builder of the firstToolOutputGuardrailExecutorBuilderFactorythatServiceLoaderfinds, looked up once, or the default one.protected ToolOutputGuardrailResultcomposeResult(ToolOutputGuardrailResult oldResult, ToolOutputGuardrailResult newResult) Composes the results likeAbstractGuardrailExecutor.composeResult(GuardrailResult, GuardrailResult), additionally making sure that a text rewrite following a contents rewrite does not lose the latter: the composed result is the contents rewrite with the text replaced.Creates an empty instance ofGuardrailExecutedEvent.GuardrailExecutedEventBuilderused for constructing observability event objects.protected ToolOutputGuardrailResultcreateFailure(List<ToolOutputGuardrailResult.Failure> failures) Creates a failure result from someGuardrailResult.Failures.protected ToolOutputGuardrailExceptioncreateGuardrailException(String message, @Nullable Throwable cause) Creates aGuardrailExceptionusing the provided message and optional cause.protected ToolOutputGuardrailResultCreates a success result.Methods inherited from class AbstractToolGuardrailExecutor
execute, executeAsync, validate, validateAsyncMethods inherited from class AbstractGuardrailExecutor
config, executeGuardrails, executeGuardrailsAsync, fireObservabilityEvent, guardrails, handleFatalResult
-
Constructor Details
-
ToolOutputGuardrailExecutor
protected ToolOutputGuardrailExecutor(ToolOutputGuardrailsConfig config, List<ToolOutputGuardrail> guardrails)
-
-
Method Details
-
createFailure
Description copied from class:AbstractGuardrailExecutorCreates a failure result from someGuardrailResult.Failures.- Specified by:
createFailurein classAbstractGuardrailExecutor<ToolOutputGuardrailsConfig, ToolOutputGuardrailRequest, ToolOutputGuardrailResult, ToolOutputGuardrail, ToolOutputGuardrailExecutedEvent, ToolOutputGuardrailResult.Failure>- Parameters:
failures- The failures- Returns:
- A
GuardrailResultcontaining the failures
-
createSuccess
Description copied from class:AbstractGuardrailExecutorCreates a success result.- Specified by:
createSuccessin classAbstractGuardrailExecutor<ToolOutputGuardrailsConfig, ToolOutputGuardrailRequest, ToolOutputGuardrailResult, ToolOutputGuardrail, ToolOutputGuardrailExecutedEvent, ToolOutputGuardrailResult.Failure>- Returns:
- A
GuardrailResultrepresenting success
-
createGuardrailException
protected ToolOutputGuardrailException createGuardrailException(String message, @Nullable Throwable cause) Description copied from class:AbstractGuardrailExecutorCreates aGuardrailExceptionusing the provided message and optional cause.- Specified by:
createGuardrailExceptionin classAbstractGuardrailExecutor<ToolOutputGuardrailsConfig, ToolOutputGuardrailRequest, ToolOutputGuardrailResult, ToolOutputGuardrail, ToolOutputGuardrailExecutedEvent, ToolOutputGuardrailResult.Failure>- Parameters:
message- The detailed message for the exception.cause- The underlying cause of the exception, or null if no cause is available.- Returns:
- A new instance of
GuardrailExceptionconstructed with the provided message and cause.
-
createEmptyObservabilityEventBuilderInstance
protected ToolOutputGuardrailExecutedEvent.ToolOutputGuardrailExecutedEventBuilder createEmptyObservabilityEventBuilderInstance()Description copied from class:AbstractGuardrailExecutorCreates an empty instance ofGuardrailExecutedEvent.GuardrailExecutedEventBuilderused for constructing observability event objects.- Specified by:
createEmptyObservabilityEventBuilderInstancein classAbstractGuardrailExecutor<ToolOutputGuardrailsConfig, ToolOutputGuardrailRequest, ToolOutputGuardrailResult, ToolOutputGuardrail, ToolOutputGuardrailExecutedEvent, ToolOutputGuardrailResult.Failure>- Returns:
- An initialized instance of
GuardrailExecutedEvent.GuardrailExecutedEventBuilderwith the appropriate type parameters.
-
composeResult
protected ToolOutputGuardrailResult composeResult(ToolOutputGuardrailResult oldResult, ToolOutputGuardrailResult newResult) Composes the results likeAbstractGuardrailExecutor.composeResult(GuardrailResult, GuardrailResult), additionally making sure that a text rewrite following a contents rewrite does not lose the latter: the composed result is the contents rewrite with the text replaced. -
builder
Creates and returns a new builder forToolOutputGuardrailExecutor: the builder of the firstToolOutputGuardrailExecutorBuilderFactorythatServiceLoaderfinds, looked up once, or the default one.- Returns:
- A
ToolOutputGuardrailExecutor.ToolOutputGuardrailExecutorBuilderused to createToolOutputGuardrailExecutorinstances
-