Class ToolOutputGuardrailRequest
java.lang.Object
dev.langchain4j.guardrail.ToolOutputGuardrailRequest
- All Implemented Interfaces:
GuardrailRequest<ToolOutputGuardrailRequest>
@Experimental
public final class ToolOutputGuardrailRequest
extends Object
implements GuardrailRequest<ToolOutputGuardrailRequest>
Represents the parameter passed to a tool output guardrail, after a tool has been executed.
- Since:
- 1.25.0
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescription@Nullable StringParses the arguments the tool was executed with (after the rewrites of the input guardrails) into a read-only map, exactly likeToolInputGuardrailRequest.argumentsAsMap(): leniently, as the default executor of local@Toolmethods does, into a deep, unmodifiable snapshot, parsed on every call.builder()@Nullable InvocationContextbooleanisError()@Nullable ObjectmemoryId()Retrieves the common parameters that are shared across guardrail checks.text()Returns the texts of allTextContents joined with\n.toolName()Replaces the text contents with a singleTextContent(placed where the first text content was, or first if there was none), keeping the non-text contents and the error flag.
-
Method Details
-
toolExecutionRequest
- Returns:
- the tool execution request, never null
-
toolSpecification
- Returns:
- the specification of the executed tool, never
null
-
toolSource
- Returns:
- the trusted origin of the tool, never null
-
requestParams
Description copied from interface:GuardrailRequestRetrieves the common parameters that are shared across guardrail checks.- Specified by:
requestParamsin interfaceGuardrailRequest<ToolOutputGuardrailRequest>- Returns:
- an instance of
GuardrailRequestParamscontaining shared parameters such as chat memory, user message template, and additional variables.
-
toolName
- Returns:
- the tool name
-
arguments
- Returns:
- the tool arguments as a JSON string, or
nullwhen the tool call has none (seeargumentsAsMap(), which gives an empty map for them)
-
argumentsAsMap
Parses the arguments the tool was executed with (after the rewrites of the input guardrails) into a read-only map, exactly likeToolInputGuardrailRequest.argumentsAsMap(): leniently, as the default executor of local@Toolmethods does, into a deep, unmodifiable snapshot, parsed on every call.They come from the tool call produced by the LLM (as the input guardrails left them), and are untrusted.
- Returns:
- the parsed arguments, never null
- Throws:
ToolArgumentsException- if the arguments are not a valid JSON object. Thrown from an output guardrail, it aborts the invocation like any other exception of a guardrail.- Since:
- 1.25.0
-
invocationContext
- Returns:
- the invocation context, or null if the request params carry none
-
memoryId
- Returns:
- the chat memory id, or null if there is no invocation context or no memory id
-
resultContents
-
isError
public boolean isError()- Returns:
- whether the tool execution resulted in an error
-
text
Returns the texts of allTextContents joined with\n. Never throws.- Returns:
- the joined text, or an empty string if there is no text content
-
withText
Replaces the text contents with a singleTextContent(placed where the first text content was, or first if there was none), keeping the non-text contents and the error flag.- Specified by:
withTextin interfaceGuardrailRequest<ToolOutputGuardrailRequest>- Parameters:
text- the new text, must not be null- Returns:
- A clone of this guardrail params with the given input or output text.
- Throws:
IllegalArgumentException- if text is null
-
toBuilder
- Returns:
- a builder initialized with the values of this request
-
builder
- Returns:
- a new builder
-