Class ToolInputGuardrailRequest
- All Implemented Interfaces:
GuardrailRequest<ToolInputGuardrailRequest>
- Since:
- 1.25.0
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescription@Nullable StringParses the tool arguments JSON into a read-only map, using the same lenient parsing as the default executor of local@Toolmethods (null or blank arguments, and the JSON literalnull, give an empty map; surrounding quotes, escaped quotes and trailing commas are normalized when the strict parse fails).builder()@Nullable InvocationContext@Nullable ObjectmemoryId()Retrieves the common parameters that are shared across guardrail checks.toolName()Replaces the arguments JSON, keeping the id and the name of the tool execution request.
-
Method Details
-
toolExecutionRequest
- Returns:
- the tool execution request, never null
-
toolSpecification
- Returns:
- the specification of the tool being executed, 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<ToolInputGuardrailRequest>- 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 tool arguments JSON into a read-only map, using the same lenient parsing as the default executor of local@Toolmethods (null or blank arguments, and the JSON literalnull, give an empty map; surrounding quotes, escaped quotes and trailing commas are normalized when the strict parse fails).This parity holds only for local
@Toolmethods. Other executors, such as MCP or programmatic ones, may parse the raw arguments differently (for example strictly);arguments()is the exact raw JSON payload the executor receives.These are the arguments of the tool call produced by the LLM and are untrusted; they are neither the AI Service method arguments (see
InvocationContext.methodArguments()) nor part of theToolSource.The result is a deep, unmodifiable snapshot: nested objects are maps, nested arrays are lists, and JSON
nullvalues are preserved as null map values. Number types depend on the JSON codec. The map is parsed on every call.If the arguments cannot be parsed, a
ToolArgumentsExceptionis thrown. A guardrail can let it propagate: the tool is then not executed, and the call is handled like an arguments error of the tool, by theToolArgumentsErrorHandlerof the AI service. The default handler fails the invocation in the blocking andTokenStreammodes, and sends the error to the LLM, so that it can correct the arguments, in theCompletableFutureandFlow.Publishermodes.- Returns:
- the parsed arguments, never null
- Throws:
ToolArgumentsException- if the arguments are not a valid JSON object (malformed JSON or a non-object root)- 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
-
withText
Replaces the arguments JSON, keeping the id and the name of the tool execution request.- Specified by:
withTextin interfaceGuardrailRequest<ToolInputGuardrailRequest>- Parameters:
text- the new arguments JSON, 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
-