Class ToolInputGuardrailResult
java.lang.Object
dev.langchain4j.guardrail.ToolInputGuardrailResult
- All Implemented Interfaces:
GuardrailResult<ToolInputGuardrailResult>
@Experimental
public final class ToolInputGuardrailResult
extends Object
implements GuardrailResult<ToolInputGuardrailResult>
The result of the validation of a
ToolInputGuardrail.
A successful result may carry rewritten tool arguments (a JSON string), which replace the arguments of the tool execution request for the guardrails that follow and for the tool execution itself.
- Since:
- 1.25.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classRepresents a tool input guardrail failure.Nested classes/interfaces inherited from interface GuardrailResult
GuardrailResult.Result -
Method Summary
Modifier and TypeMethodDescriptionbooleanGets the text of the error tool result that reports the failures of this result to the LLM: the messages of all the failures, joined with\nin chain order.<F extends GuardrailResult.Failure>
List<F> failures()inthashCode()result()The result of the guardrailGets the tool arguments as the guardrail chain left them: the arguments rewritten by the guardrails that ran, or empty if none of them rewrote the arguments.static ToolInputGuardrailResultsuccess()Gets a successful tool input guardrail result.@Nullable StringThe message of the successful resultstatic ToolInputGuardrailResultsuccessWith(@Nullable String rewrittenArguments) Produces a successful result with rewritten tool arguments.static ToolInputGuardrailResultsuccessWithArguments(Map<String, ?> rewrittenArguments) Produces a successful result with rewritten tool arguments, given as a map of argument names to values.toString()Methods inherited from interface GuardrailResult
asString, getFirstFailureException, hasRewrittenResult, isFatal, isSuccess, validatedBy
-
Method Details
-
success
Gets a successful tool input guardrail result.- Returns:
- a successful result without any rewrite
-
successWith
Produces a successful result with rewritten tool arguments.- Parameters:
rewrittenArguments- the new arguments of the tool, as a JSON object (otherwise the executor fails the call with aToolInputGuardrailException). Whennull, the result is a plain success.- Returns:
- a successful result carrying the rewritten arguments
-
successWithArguments
Produces a successful result with rewritten tool arguments, given as a map of argument names to values. The map is serialized to a JSON object right away, with the same JSON codec thatToolInputGuardrailRequest.argumentsAsMap()parses the arguments with, so quotes and other special characters in the values need no escaping.Unlike
successWith(String), anullmap is rejected: a guardrail that redacts the arguments and returnsnullby mistake must not let the original arguments through.- Parameters:
rewrittenArguments- the new arguments of the tool, by name; must not benull- Returns:
- a successful result carrying the rewritten arguments
- Throws:
IllegalArgumentException- ifrewrittenArgumentsisnullRuntimeException- if a value has no JSON representation; thrown from a guardrail, it is a fatal failure of the guardrail, before the tool runs
-
result
Description copied from interface:GuardrailResultThe result of the guardrail- Specified by:
resultin interfaceGuardrailResult<ToolInputGuardrailResult>
-
successfulText
Description copied from interface:GuardrailResultThe message of the successful result- Specified by:
successfulTextin interfaceGuardrailResult<ToolInputGuardrailResult>- Returns:
- the rewritten tool arguments (a JSON string), or
nullif the arguments were not rewritten
-
rewrittenArguments
Gets the tool arguments as the guardrail chain left them: the arguments rewritten by the guardrails that ran, or empty if none of them rewrote the arguments.Unlike
successfulText(), this is also available on a failed result, when a guardrail that ran before the failing one rewrote the arguments. The tool is not executed then, but what the caller reports for the rejected call is the latest request state.- Returns:
- the rewritten tool arguments (a JSON string), if any guardrail of the chain rewrote them
-
failureMessage
Gets the text of the error tool result that reports the failures of this result to the LLM: the messages of all the failures, joined with\nin chain order. No framework text is added.- Returns:
- the joined failure messages, or an empty string if there are no failures
-
failures
- Specified by:
failuresin interfaceGuardrailResult<ToolInputGuardrailResult>- Returns:
- The list of failures eventually resulting from a set of validations.
-
toString
-
equals
-
hashCode
-