Interface GuardrailService
- All Known Implementing Classes:
AbstractGuardrailService
public interface GuardrailService
Defines a service for executing guardrails associated with methods in an AI service.
Guardrails are constraints or validations applied either to input or output of a method.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionClass
<?> Retrieves the class representing the AI service to which the guardrails apply.static GuardrailService.Builder
Creates a new instance ofGuardrailService.Builder
for the specified AI service class.default <MethodKey>
UserMessageexecuteGuardrails
(MethodKey method, InputGuardrailRequest params) Executes the input guardrails associated with the given method and parameters, and retrieves a modified or validatedUserMessage
based on the result.default <MethodKey,
T>
TexecuteGuardrails
(MethodKey method, OutputGuardrailRequest params) Executes the guardrails associated with a given method and parameters, returning the appropriate response.<MethodKey>
InputGuardrailResultexecuteInputGuardrails
(MethodKey method, InputGuardrailRequest params) Executes the input guardrails associated with a givenMethod
<MethodKey>
OutputGuardrailResultexecuteOutputGuardrails
(MethodKey method, OutputGuardrailRequest params) Executes the output guardrails associated with a givenMethod
.<MethodKey>
booleanhasInputGuardrails
(MethodKey method) Whether or not a method has any input guardrails associated with it<MethodKey>
booleanhasOutputGuardrails
(MethodKey method) Whether or not a method has any output guardrails associated with it
-
Method Details
-
aiServiceClass
Class<?> aiServiceClass()Retrieves the class representing the AI service to which the guardrails apply.- Returns:
- The
Class
object representing the AI service.
-
executeInputGuardrails
<MethodKey> InputGuardrailResult executeInputGuardrails(MethodKey method, InputGuardrailRequest params) Executes the input guardrails associated with a givenMethod
- Type Parameters:
MethodKey
- > The type of the method key, representing a unique identifier for methods.- Parameters:
method
- The method whose input guardrails are to be executed.params
- The parameters to validate against the input guardrails. Must not be null.- Returns:
- The result of executing the input guardrails, encapsulated in an
InputGuardrailResult
. If no guardrails are associated with the method, a successful result is returned by default.
-
executeGuardrails
Executes the input guardrails associated with the given method and parameters, and retrieves a modified or validatedUserMessage
based on the result.- Type Parameters:
MethodKey
- The type of the method key, representing a unique identifier for methods.- Parameters:
method
- The method whose input guardrails are to be executed. Nullable.params
- The parameters to validate against the input guardrails. Must not be null.- Returns:
- A
UserMessage
derived from the provided parameters and the result of the input guardrails execution. If guardrails are applied successfully, a potentially rewritten user message is returned. If no guardrails are associated with the method, the original user message is returned.
-
executeOutputGuardrails
<MethodKey> OutputGuardrailResult executeOutputGuardrails(MethodKey method, OutputGuardrailRequest params) Executes the output guardrails associated with a givenMethod
.- Type Parameters:
MethodKey
- > The type of the method key, representing a unique identifier for methods.- Parameters:
method
- The method whose output guardrails are to be executed.params
- The parameters to validate against the output guardrails. Must not be null.- Returns:
- The result of executing the output guardrails, encapsulated in an
OutputGuardrailResult
. If no guardrails are associated with the method, a successful result is returned by default.
-
hasInputGuardrails
<MethodKey> boolean hasInputGuardrails(MethodKey method) Whether or not a method has any input guardrails associated with it- Type Parameters:
MethodKey
- > The type of the method key, representing a unique identifier for methods.- Parameters:
method
- The method- Returns:
true
Ifmethod
has input guardrails.false
otherwise
-
hasOutputGuardrails
<MethodKey> boolean hasOutputGuardrails(MethodKey method) Whether or not a method has any output guardrails associated with it- Type Parameters:
MethodKey
- > The type of the method key, representing a unique identifier for methods.- Parameters:
method
- The method- Returns:
true
Ifmethod
has output guardrails.false
otherwise
-
executeGuardrails
Executes the guardrails associated with a given method and parameters, returning the appropriate response.- Type Parameters:
MethodKey
- The type of the method key, representing a unique identifier for methods.T
- The type of response to produce- Parameters:
method
- The method whose output guardrails are to be executed. Nullable.params
- The parameters to validate against the output guardrails. Must not be null.- Returns:
- A
ChatResponse
that encapsulates the output of executing the guardrails based on the provided parameters.
-
builder
Creates a new instance ofGuardrailService.Builder
for the specified AI service class.- Parameters:
aiServiceClass
- TheClass
object representing the AI service for which the builder is being created.- Returns:
- A
GuardrailService.Builder
instance initialized with the specified AI service class.
-