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 ClassesModifier and TypeInterfaceDescriptionstatic interfaceBuilder class for buildingGuardrailServiceinstances -
Method Summary
Modifier and TypeMethodDescriptionClass<?> Retrieves the class representing the AI service to which the guardrails apply.static GuardrailService.BuilderCreates a new instance ofGuardrailService.Builderfor the specified AI service class.default <MethodKey>
UserMessageexecuteGuardrails(MethodKey method, InputGuardrailRequest request) Executes the input guardrails associated with the given method and parameters, and retrieves a modified or validatedUserMessagebased on the result.default <MethodKey, T>
TexecuteGuardrails(MethodKey method, OutputGuardrailRequest request) Executes the guardrails associated with a given method and parameters, returning the appropriate response.<MethodKey>
InputGuardrailResultexecuteInputGuardrails(MethodKey method, InputGuardrailRequest request) Executes the input guardrails associated with a givenMethod<MethodKey>
OutputGuardrailResultexecuteOutputGuardrails(MethodKey method, OutputGuardrailRequest request) 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
Classobject representing the AI service.
-
executeInputGuardrails
<MethodKey> InputGuardrailResult executeInputGuardrails(MethodKey method, InputGuardrailRequest request) 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.request- 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 validatedUserMessagebased 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.request- The parameters to validate against the input guardrails. Must not be null.- Returns:
- A
UserMessagederived 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 request) 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.request- 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:
trueIfmethodhas input guardrails.falseotherwise
-
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:
trueIfmethodhas output guardrails.falseotherwise
-
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.request- The parameters to validate against the output guardrails. Must not be null.- Returns:
- A
ChatResponsethat encapsulates the output of executing the guardrails based on the provided parameters.
-
builder
Creates a new instance ofGuardrailService.Builderfor the specified AI service class.Attempts to retrieve an instance through a
GuardrailServiceBuilderFactory, if available. If no factory is present, it uses its own default instance.- Parameters:
aiServiceClass- TheClassobject representing the AI service for which the builder is being created.- Returns:
- A
GuardrailService.Builderinstance initialized with the specified AI service class.
-