Interface ToolInputGuardrailsConfig
- All Superinterfaces:
GuardrailsConfig
It sets the arguments rewrite note: the chat memory keeps a tool call as the LLM made it, so when an input
guardrail changed the value of an argument the LLM sent, the tool result that the LLM gets says so, in a note
followed by the result of the tool. The values are compared parsed, so a rewrite that only changes the spacing
or the order of the keys adds no note. Otherwise the LLM would read, on every later turn, that the call it made ran as it made it (a transfer
of 10000 that a guardrail capped to 1000, for example). The note is in the first text content of the result (a
result without text gets it as a text content of its own, in front of the other contents), and only the LLM
gets it: the events and toolExecutions() keep the result of the tool as is.
Frameworks that extend this library (like Quarkus or Spring) may provide their own implementations of this configuration.
- Since:
- 1.25.0
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceBuilder forToolInputGuardrailsConfiginstances. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PromptTemplateThe default template of the arguments rewrite note: the note in its own tag, then the result of the tool. -
Method Summary
Modifier and TypeMethodDescriptiondefault PromptTemplateThe template of the text of a tool result whose call an input guardrail changed.builder()Gets a builder instance for buildingToolInputGuardrailsConfiginstances: the builder of the firstToolInputGuardrailsConfigBuilderFactorythatServiceLoaderfinds, looked up once, or the default one.default booleanWhether the tool result that the LLM gets carries the arguments rewrite note when an input guardrail changed the arguments of the call.
-
Field Details
-
DEFAULT_ARGUMENTS_REWRITE_NOTE_TEMPLATE
The default template of the arguments rewrite note: the note in its own tag, then the result of the tool.
-
-
Method Details
-
isArgumentsRewriteNoteEnabled
default boolean isArgumentsRewriteNoteEnabled()Whether the tool result that the LLM gets carries the arguments rewrite note when an input guardrail changed the arguments of the call. Enabled by default.- Returns:
trueif the note is added
-
argumentsRewriteNoteTemplate
The template of the text of a tool result whose call an input guardrail changed. Its variables:{{arguments}}: the changed arguments, as a JSON object: the values the LLM sent whose values changed, with their new values (a removed one asnull). An object argument is compared field by field, and only its changed fields are in it, nested where they are nested; a list is compared, and shown, as a whole. A value that a guardrail added is never in it, except inside a list that changed.{{result}}: the text of the result of the tool. Required, so the LLM still gets the result.
{{arguments}}or{{result}}in the arguments or in the result is not expanded. The date and time variables ofPromptTemplatecan be used too; any other variable makes the template invalid, which the AI service reports when it is built. Defaults toDEFAULT_ARGUMENTS_REWRITE_NOTE_TEMPLATE.The note is stored in the chat memory. A value a guardrail added (a tenant or a user id from the invocation, for example) is not in it, but a guardrail that overwrites a value the LLM sent with a value the LLM must not see does show that value. The LLM decides which keys it sends (a prompt injection can make it send any key), so a value a guardrail adds is an overwrite whenever the LLM sends that key too: for a guardrail that puts in a value the LLM must not see, leave
{{arguments}}out of the template, or disable the note.- Returns:
- the template, which contains
{{result}}
-
builder
Gets a builder instance for buildingToolInputGuardrailsConfiginstances: the builder of the firstToolInputGuardrailsConfigBuilderFactorythatServiceLoaderfinds, looked up once, or the default one.- Returns:
- A
ToolInputGuardrailsConfig.ToolInputGuardrailsConfigBuilderfor buildingToolInputGuardrailsConfiginstances.
-