Class Guardrail
java.lang.Object
software.amazon.jsii.JsiiObject
software.constructs.Construct
software.amazon.awscdk.Resource
software.amazon.awscdk.services.bedrock.alpha.GuardrailBase
software.amazon.awscdk.services.bedrock.alpha.Guardrail
- All Implemented Interfaces:
IResource
,IGuardrail
,software.amazon.jsii.JsiiSerializable
,software.constructs.IConstruct
,software.constructs.IDependable
@Generated(value="jsii-pacmak/1.113.0 (build fc68b25)",
date="2025-09-02T11:25:42.806Z")
@Stability(Experimental)
public class Guardrail
extends GuardrailBase
(experimental) Class to create a Guardrail with CDK.
Example:
Guardrail guardrail = Guardrail.Builder.create(this, "bedrockGuardrails") .guardrailName("my-BedrockGuardrails") .build(); // Add regex filter with input/output actions guardrail.addRegexFilter(RegexFilter.builder() .name("TestRegexFilter") .pattern("test-pattern") .action(GuardrailAction.ANONYMIZE) // below props are optional .description("This is a test regex filter") .inputAction(GuardrailAction.BLOCK) .inputEnabled(true) .outputAction(GuardrailAction.ANONYMIZE) .outputEnabled(true) .build());
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
(experimental) A fluent builder forGuardrail
.Nested classes/interfaces inherited from class software.amazon.jsii.JsiiObject
software.amazon.jsii.JsiiObject.InitializationMode
Nested classes/interfaces inherited from interface software.constructs.IConstruct
software.constructs.IConstruct.Jsii$Default
Nested classes/interfaces inherited from interface software.amazon.awscdk.services.bedrock.alpha.IGuardrail
IGuardrail.Jsii$Default
Nested classes/interfaces inherited from interface software.amazon.awscdk.IResource
IResource.Jsii$Default
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
(experimental) Uniquely identifies this class. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Guardrail
(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) protected
Guardrail
(software.amazon.jsii.JsiiObjectRef objRef) Guardrail
(software.constructs.Construct scope, String id, GuardrailProps props) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addContentFilter
(ContentFilter filter) (experimental) Adds a content filter to the guardrail.void
(experimental) Adds a contextual grounding filter to the guardrail.void
addDeniedTopicFilter
(Topic filter) (experimental) Adds a denied topic filter to the guardrail.void
(experimental) Adds a managed word list filter to the guardrail.void
addPIIFilter
(PIIFilter filter) (experimental) Adds a PII filter to the guardrail.void
addRegexFilter
(RegexFilter filter) (experimental) Adds a regex filter to the guardrail.void
addWordFilter
(WordFilter filter) (experimental) Adds a word filter to the guardrail.void
addWordFilterFromFile
(String filePath) (experimental) Adds a word filter to the guardrail.void
addWordFilterFromFile
(String filePath, GuardrailAction inputAction) (experimental) Adds a word filter to the guardrail.void
addWordFilterFromFile
(String filePath, GuardrailAction inputAction, GuardrailAction outputAction) (experimental) Adds a word filter to the guardrail.void
addWordFilterFromFile
(String filePath, GuardrailAction inputAction, GuardrailAction outputAction, Boolean inputEnabled) (experimental) Adds a word filter to the guardrail.void
addWordFilterFromFile
(String filePath, GuardrailAction inputAction, GuardrailAction outputAction, Boolean inputEnabled, Boolean outputEnabled) (experimental) Adds a word filter to the guardrail.(experimental) Create a version for the guardrail.createVersion
(String description) (experimental) Create a version for the guardrail.static IGuardrail
fromCfnGuardrail
(CfnGuardrail cfnGuardrail) (experimental) Import a low-level L1 Cfn Guardrail.static IGuardrail
fromGuardrailAttributes
(software.constructs.Construct scope, String id, GuardrailAttributes attrs) (experimental) Import a guardrail given its attributes.(experimental) The message to return when the guardrail blocks a prompt.(experimental) The message to return when the guardrail blocks a model response.(experimental) The content filters applied by the guardrail.(experimental) The tier that your guardrail uses for content filters.(experimental) The contextual grounding filters applied by the guardrail.(experimental) The cross-region configuration for the guardrail.(experimental) The denied topic filters applied by the guardrail.(experimental) The ARN of the guardrail.(experimental) The ID of the guardrail.getHash()
(experimental) The computed hash of the guardrail properties.(experimental) The KMS key used to encrypt data.(experimental) When this guardrail was last updated.(experimental) The managed word list filters applied by the guardrail.getName()
(experimental) The name of the guardrail.(experimental) The PII filters applied by the guardrail.(experimental) The regex filters applied by the guardrail.(experimental) The tier that your guardrail uses for denied topic filters.(experimental) The word filters applied by the guardrail.Methods inherited from class software.amazon.awscdk.services.bedrock.alpha.GuardrailBase
getGuardrailVersion, grant, grantApply, metric, metric, metricAll, metricAll, metricAllInvocationLatency, metricAllInvocationLatency, metricAllInvocations, metricAllInvocations, metricAllInvocationsIntervened, metricAllInvocationsIntervened, metricAllTextUnitCount, metricAllTextUnitCount, metricInvocationClientErrors, metricInvocationClientErrors, metricInvocationLatency, metricInvocationLatency, metricInvocations, metricInvocations, metricInvocationServerErrors, metricInvocationServerErrors, metricInvocationsIntervened, metricInvocationsIntervened, metricInvocationThrottles, metricInvocationThrottles, metricTextUnitCount, metricTextUnitCount, updateVersion
Methods inherited from class software.amazon.awscdk.Resource
applyRemovalPolicy, generatePhysicalName, getEnv, getPhysicalName, getResourceArnAttribute, getResourceNameAttribute, getStack, isOwnedResource, isResource
Methods inherited from class software.constructs.Construct
getNode, isConstruct, toString
Methods inherited from class software.amazon.jsii.JsiiObject
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSet
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface software.constructs.IConstruct
getNode
Methods inherited from interface software.amazon.awscdk.IResource
applyRemovalPolicy, getEnv, getStack
Methods inherited from interface software.amazon.jsii.JsiiSerializable
$jsii$toJson
-
Field Details
-
PROPERTY_INJECTION_ID
(experimental) Uniquely identifies this class.
-
-
Constructor Details
-
Guardrail
protected Guardrail(software.amazon.jsii.JsiiObjectRef objRef) -
Guardrail
protected Guardrail(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) -
Guardrail
@Stability(Experimental) public Guardrail(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull GuardrailProps props) - Parameters:
scope
- This parameter is required.id
- This parameter is required.props
- This parameter is required.
-
-
Method Details
-
fromCfnGuardrail
@Stability(Experimental) @NotNull public static IGuardrail fromCfnGuardrail(@NotNull CfnGuardrail cfnGuardrail) (experimental) Import a low-level L1 Cfn Guardrail.- Parameters:
cfnGuardrail
- This parameter is required.
-
fromGuardrailAttributes
@Stability(Experimental) @NotNull public static IGuardrail fromGuardrailAttributes(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull GuardrailAttributes attrs) (experimental) Import a guardrail given its attributes.- Parameters:
scope
- This parameter is required.id
- This parameter is required.attrs
- This parameter is required.
-
addContentFilter
(experimental) Adds a content filter to the guardrail.- Parameters:
filter
- The content filter to add. This parameter is required.
-
addContextualGroundingFilter
@Stability(Experimental) public void addContextualGroundingFilter(@NotNull ContextualGroundingFilter filter) (experimental) Adds a contextual grounding filter to the guardrail.- Parameters:
filter
- The contextual grounding filter to add. This parameter is required.
-
addDeniedTopicFilter
(experimental) Adds a denied topic filter to the guardrail.- Parameters:
filter
- The denied topic filter to add. This parameter is required.
-
addManagedWordListFilter
(experimental) Adds a managed word list filter to the guardrail.- Parameters:
filter
- The managed word list filter to add. This parameter is required.
-
addPIIFilter
(experimental) Adds a PII filter to the guardrail.- Parameters:
filter
- The PII filter to add. This parameter is required.
-
addRegexFilter
(experimental) Adds a regex filter to the guardrail.- Parameters:
filter
- The regex filter to add. This parameter is required.
-
addWordFilter
(experimental) Adds a word filter to the guardrail.- Parameters:
filter
- The word filter to add. This parameter is required.
-
addWordFilterFromFile
@Stability(Experimental) public void addWordFilterFromFile(@NotNull String filePath, @Nullable GuardrailAction inputAction, @Nullable GuardrailAction outputAction, @Nullable Boolean inputEnabled, @Nullable Boolean outputEnabled) (experimental) Adds a word filter to the guardrail.- Parameters:
filePath
- The location of the word filter file. This parameter is required.inputAction
-outputAction
-inputEnabled
-outputEnabled
-
-
addWordFilterFromFile
@Stability(Experimental) public void addWordFilterFromFile(@NotNull String filePath, @Nullable GuardrailAction inputAction, @Nullable GuardrailAction outputAction, @Nullable Boolean inputEnabled) (experimental) Adds a word filter to the guardrail.- Parameters:
filePath
- The location of the word filter file. This parameter is required.inputAction
-outputAction
-inputEnabled
-
-
addWordFilterFromFile
@Stability(Experimental) public void addWordFilterFromFile(@NotNull String filePath, @Nullable GuardrailAction inputAction, @Nullable GuardrailAction outputAction) (experimental) Adds a word filter to the guardrail.- Parameters:
filePath
- The location of the word filter file. This parameter is required.inputAction
-outputAction
-
-
addWordFilterFromFile
@Stability(Experimental) public void addWordFilterFromFile(@NotNull String filePath, @Nullable GuardrailAction inputAction) (experimental) Adds a word filter to the guardrail.- Parameters:
filePath
- The location of the word filter file. This parameter is required.inputAction
-
-
addWordFilterFromFile
(experimental) Adds a word filter to the guardrail.- Parameters:
filePath
- The location of the word filter file. This parameter is required.
-
createVersion
(experimental) Create a version for the guardrail.- Parameters:
description
- The description of the version.- Returns:
- The guardrail version.
-
createVersion
(experimental) Create a version for the guardrail.- Returns:
- The guardrail version.
-
getBlockedInputMessaging
(experimental) The message to return when the guardrail blocks a prompt.Default: "Sorry, your query violates our usage policy."
-
getBlockedOutputsMessaging
(experimental) The message to return when the guardrail blocks a model response.Default: "Sorry, I am unable to answer your question because of our usage policy."
-
getContentFilters
(experimental) The content filters applied by the guardrail. -
getContentFiltersTierConfig
(experimental) The tier that your guardrail uses for content filters.Consider using a tier that balances performance, accuracy, and compatibility with your existing generative AI workflows.
Default: filters.TierConfig.CLASSIC
-
getContextualGroundingFilters
@Stability(Experimental) @NotNull public List<ContextualGroundingFilter> getContextualGroundingFilters()(experimental) The contextual grounding filters applied by the guardrail. -
getDeniedTopics
(experimental) The denied topic filters applied by the guardrail. -
getGuardrailArn
(experimental) The ARN of the guardrail.- Specified by:
getGuardrailArn
in interfaceIGuardrail
- Specified by:
getGuardrailArn
in classGuardrailBase
-
getGuardrailId
(experimental) The ID of the guardrail.- Specified by:
getGuardrailId
in interfaceIGuardrail
- Specified by:
getGuardrailId
in classGuardrailBase
-
getHash
(experimental) The computed hash of the guardrail properties. -
getManagedWordListFilters
(experimental) The managed word list filters applied by the guardrail. -
getName
(experimental) The name of the guardrail. -
getPiiFilters
(experimental) The PII filters applied by the guardrail. -
getRegexFilters
(experimental) The regex filters applied by the guardrail. -
getTopicsTierConfig
(experimental) The tier that your guardrail uses for denied topic filters.Default: filters.TierConfig.CLASSIC
-
getWordFilters
(experimental) The word filters applied by the guardrail. -
getCrossRegionConfig
(experimental) The cross-region configuration for the guardrail. -
getKmsKey
(experimental) The KMS key used to encrypt data.Default: undefined - "Data is encrypted by default with a key that AWS owns and manages for you"
- Specified by:
getKmsKey
in interfaceIGuardrail
- Specified by:
getKmsKey
in classGuardrailBase
-
getLastUpdated
(experimental) When this guardrail was last updated.- Specified by:
getLastUpdated
in interfaceIGuardrail
- Specified by:
getLastUpdated
in classGuardrailBase
-