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:
IEnvironmentAware,IResource,IGuardrail,software.amazon.jsii.JsiiSerializable,software.constructs.IConstruct,software.constructs.IDependable
@Generated(value="jsii-pacmak/1.120.0 (build 192dc88)",
date="2025-12-05T22:26:49.483Z")
@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.InitializationModeNested classes/interfaces inherited from interface software.constructs.IConstruct
software.constructs.IConstruct.Jsii$DefaultNested classes/interfaces inherited from interface software.amazon.awscdk.services.bedrock.alpha.IGuardrail
IGuardrail.Jsii$DefaultNested 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
ConstructorsModifierConstructorDescriptionprotectedGuardrail(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) protectedGuardrail(software.amazon.jsii.JsiiObjectRef objRef) Guardrail(software.constructs.Construct scope, String id, GuardrailProps props) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddContentFilter(ContentFilter filter) (experimental) Adds a content filter to the guardrail.void(experimental) Adds a contextual grounding filter to the guardrail.voidaddDeniedTopicFilter(Topic filter) (experimental) Adds a denied topic filter to the guardrail.void(experimental) Adds a managed word list filter to the guardrail.voidaddPIIFilter(PIIFilter filter) (experimental) Adds a PII filter to the guardrail.voidaddRegexFilter(RegexFilter filter) (experimental) Adds a regex filter to the guardrail.voidaddWordFilter(WordFilter filter) (experimental) Adds a word filter to the guardrail.voidaddWordFilterFromFile(String filePath) (experimental) Adds a word filter to the guardrail.voidaddWordFilterFromFile(String filePath, GuardrailAction inputAction) (experimental) Adds a word filter to the guardrail.voidaddWordFilterFromFile(String filePath, GuardrailAction inputAction, GuardrailAction outputAction) (experimental) Adds a word filter to the guardrail.voidaddWordFilterFromFile(String filePath, GuardrailAction inputAction, GuardrailAction outputAction, Boolean inputEnabled) (experimental) Adds a word filter to the guardrail.voidaddWordFilterFromFile(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 IGuardrailfromCfnGuardrail(CfnGuardrail cfnGuardrail) (experimental) Import a low-level L1 Cfn Guardrail.static IGuardrailfromGuardrailAttributes(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, updateVersionMethods inherited from class software.amazon.awscdk.Resource
applyRemovalPolicy, generatePhysicalName, getEnv, getPhysicalName, getResourceArnAttribute, getResourceNameAttribute, getStack, isOwnedResource, isResourceMethods inherited from class software.constructs.Construct
getNode, isConstruct, toStringMethods inherited from class software.amazon.jsii.JsiiObject
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSetMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface software.constructs.IConstruct
getNodeMethods inherited from interface software.amazon.awscdk.interfaces.IEnvironmentAware
getEnvMethods inherited from interface software.amazon.awscdk.IResource
applyRemovalPolicy, getStackMethods 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:
getGuardrailArnin interfaceIGuardrail- Specified by:
getGuardrailArnin classGuardrailBase
-
getGuardrailId
(experimental) The ID of the guardrail.- Specified by:
getGuardrailIdin interfaceIGuardrail- Specified by:
getGuardrailIdin 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:
getKmsKeyin interfaceIGuardrail- Specified by:
getKmsKeyin classGuardrailBase
-
getLastUpdated
(experimental) When this guardrail was last updated.- Specified by:
getLastUpdatedin interfaceIGuardrail- Specified by:
getLastUpdatedin classGuardrailBase
-