Class CfnGuardrail

java.lang.Object
software.amazon.jsii.JsiiObject
software.constructs.Construct
All Implemented Interfaces:
IInspectable, ITaggableV2, software.amazon.jsii.JsiiSerializable, software.constructs.IConstruct, software.constructs.IDependable

@Generated(value="jsii-pacmak/1.101.0 (build b95fe5d)", date="2024-07-12T19:33:58.308Z") @Stability(Stable) public class CfnGuardrail extends CfnResource implements IInspectable, ITaggableV2
Creates a guardrail to block topics and to implement safeguards for your generative AI applications.

You can configure the following policies in a guardrail to avoid undesirable and harmful content, filter out denied topics and words, and remove sensitive information for privacy protection.

  • Content filters - Adjust filter strengths to block input prompts or model responses containing harmful content.
  • Denied topics - Define a set of topics that are undesirable in the context of your application. These topics will be blocked if detected in user queries or model responses.
  • Word filters - Configure filters to block undesirable words, phrases, and profanity. Such words can include offensive terms, competitor names etc.
  • Sensitive information filters - Block or mask sensitive information such as personally identifiable information (PII) or custom regex in user inputs and model responses.

In addition to the above policies, you can also configure the messages to be returned to the user if a user input or model response is in violation of the policies defined in the guardrail.

For more information, see Guardrails for Amazon Bedrock in the Amazon Bedrock User Guide .

Example:

 // The code below shows an example of how to instantiate this type.
 // The values are placeholders you should change.
 import software.amazon.awscdk.services.bedrock.*;
 CfnGuardrail cfnGuardrail = CfnGuardrail.Builder.create(this, "MyCfnGuardrail")
         .blockedInputMessaging("blockedInputMessaging")
         .blockedOutputsMessaging("blockedOutputsMessaging")
         .name("name")
         // the properties below are optional
         .contentPolicyConfig(ContentPolicyConfigProperty.builder()
                 .filtersConfig(List.of(ContentFilterConfigProperty.builder()
                         .inputStrength("inputStrength")
                         .outputStrength("outputStrength")
                         .type("type")
                         .build()))
                 .build())
         .description("description")
         .kmsKeyArn("kmsKeyArn")
         .sensitiveInformationPolicyConfig(SensitiveInformationPolicyConfigProperty.builder()
                 .piiEntitiesConfig(List.of(PiiEntityConfigProperty.builder()
                         .action("action")
                         .type("type")
                         .build()))
                 .regexesConfig(List.of(RegexConfigProperty.builder()
                         .action("action")
                         .name("name")
                         .pattern("pattern")
                         // the properties below are optional
                         .description("description")
                         .build()))
                 .build())
         .tags(List.of(CfnTag.builder()
                 .key("key")
                 .value("value")
                 .build()))
         .topicPolicyConfig(TopicPolicyConfigProperty.builder()
                 .topicsConfig(List.of(TopicConfigProperty.builder()
                         .definition("definition")
                         .name("name")
                         .type("type")
                         // the properties below are optional
                         .examples(List.of("examples"))
                         .build()))
                 .build())
         .wordPolicyConfig(WordPolicyConfigProperty.builder()
                 .managedWordListsConfig(List.of(ManagedWordsConfigProperty.builder()
                         .type("type")
                         .build()))
                 .wordsConfig(List.of(WordConfigProperty.builder()
                         .text("text")
                         .build()))
                 .build())
         .build();
 

See Also:
  • Field Details

    • CFN_RESOURCE_TYPE_NAME

      @Stability(Stable) public static final String CFN_RESOURCE_TYPE_NAME
      The CloudFormation resource type name for this resource class.
  • Constructor Details

    • CfnGuardrail

      protected CfnGuardrail(software.amazon.jsii.JsiiObjectRef objRef)
    • CfnGuardrail

      protected CfnGuardrail(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
    • CfnGuardrail

      @Stability(Stable) public CfnGuardrail(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull CfnGuardrailProps props)
      Parameters:
      scope - Scope in which this resource is defined. This parameter is required.
      id - Construct identifier for this resource (unique in its scope). This parameter is required.
      props - Resource properties. This parameter is required.
  • Method Details

    • inspect

      @Stability(Stable) public void inspect(@NotNull TreeInspector inspector)
      Examines the CloudFormation resource and discloses attributes.

      Specified by:
      inspect in interface IInspectable
      Parameters:
      inspector - tree inspector to collect and process attributes. This parameter is required.
    • renderProperties

      @Stability(Stable) @NotNull protected Map<String,Object> renderProperties(@NotNull Map<String,Object> props)
      Overrides:
      renderProperties in class CfnResource
      Parameters:
      props - This parameter is required.
    • getAttrCreatedAt

      @Stability(Stable) @NotNull public String getAttrCreatedAt()
      The date and time at which the guardrail was created.
    • getAttrFailureRecommendations

      @Stability(Stable) @NotNull public List<String> getAttrFailureRecommendations()
      Appears if the status of the guardrail is FAILED .

      A list of recommendations to carry out before retrying the request.

    • getAttrGuardrailArn

      @Stability(Stable) @NotNull public String getAttrGuardrailArn()
      The ARN of the guardrail.
    • getAttrGuardrailId

      @Stability(Stable) @NotNull public String getAttrGuardrailId()
      The unique identifier of the guardrail.
    • getAttrStatus

      @Stability(Stable) @NotNull public String getAttrStatus()
      The status of the guardrail.
    • getAttrStatusReasons

      @Stability(Stable) @NotNull public List<String> getAttrStatusReasons()
      Appears if the status is FAILED .

      A list of reasons for why the guardrail failed to be created, updated, versioned, or deleted.

    • getAttrUpdatedAt

      @Stability(Stable) @NotNull public String getAttrUpdatedAt()
      The date and time at which the guardrail was last updated.
    • getAttrVersion

      @Stability(Stable) @NotNull public String getAttrVersion()
      The version of the guardrail that was created.

      This value will always be DRAFT .

    • getCdkTagManager

      @Stability(Stable) @NotNull public TagManager getCdkTagManager()
      Tag Manager which manages the tags for this resource.
      Specified by:
      getCdkTagManager in interface ITaggableV2
    • getCfnProperties

      @Stability(Stable) @NotNull protected Map<String,Object> getCfnProperties()
      Overrides:
      getCfnProperties in class CfnResource
    • getBlockedInputMessaging

      @Stability(Stable) @NotNull public String getBlockedInputMessaging()
      The message to return when the guardrail blocks a prompt.
    • setBlockedInputMessaging

      @Stability(Stable) public void setBlockedInputMessaging(@NotNull String value)
      The message to return when the guardrail blocks a prompt.
    • getBlockedOutputsMessaging

      @Stability(Stable) @NotNull public String getBlockedOutputsMessaging()
      The message to return when the guardrail blocks a model response.
    • setBlockedOutputsMessaging

      @Stability(Stable) public void setBlockedOutputsMessaging(@NotNull String value)
      The message to return when the guardrail blocks a model response.
    • getName

      @Stability(Stable) @NotNull public String getName()
      The name of the guardrail.
    • setName

      @Stability(Stable) public void setName(@NotNull String value)
      The name of the guardrail.
    • getContentPolicyConfig

      @Stability(Stable) @Nullable public Object getContentPolicyConfig()
      The content filter policies to configure for the guardrail.
    • setContentPolicyConfig

      @Stability(Stable) public void setContentPolicyConfig(@Nullable IResolvable value)
      The content filter policies to configure for the guardrail.
    • setContentPolicyConfig

      @Stability(Stable) public void setContentPolicyConfig(@Nullable CfnGuardrail.ContentPolicyConfigProperty value)
      The content filter policies to configure for the guardrail.
    • getDescription

      @Stability(Stable) @Nullable public String getDescription()
      A description of the guardrail.
    • setDescription

      @Stability(Stable) public void setDescription(@Nullable String value)
      A description of the guardrail.
    • getKmsKeyArn

      @Stability(Stable) @Nullable public String getKmsKeyArn()
      The ARN of the AWS KMS key that you use to encrypt the guardrail.
    • setKmsKeyArn

      @Stability(Stable) public void setKmsKeyArn(@Nullable String value)
      The ARN of the AWS KMS key that you use to encrypt the guardrail.
    • getSensitiveInformationPolicyConfig

      @Stability(Stable) @Nullable public Object getSensitiveInformationPolicyConfig()
      The sensitive information policy to configure for the guardrail.
    • setSensitiveInformationPolicyConfig

      @Stability(Stable) public void setSensitiveInformationPolicyConfig(@Nullable IResolvable value)
      The sensitive information policy to configure for the guardrail.
    • setSensitiveInformationPolicyConfig

      @Stability(Stable) public void setSensitiveInformationPolicyConfig(@Nullable CfnGuardrail.SensitiveInformationPolicyConfigProperty value)
      The sensitive information policy to configure for the guardrail.
    • getTags

      @Stability(Stable) @Nullable public List<CfnTag> getTags()
      The tags that you want to attach to the guardrail.
    • setTags

      @Stability(Stable) public void setTags(@Nullable List<CfnTag> value)
      The tags that you want to attach to the guardrail.
    • getTopicPolicyConfig

      @Stability(Stable) @Nullable public Object getTopicPolicyConfig()
      The topic policies to configure for the guardrail.
    • setTopicPolicyConfig

      @Stability(Stable) public void setTopicPolicyConfig(@Nullable IResolvable value)
      The topic policies to configure for the guardrail.
    • setTopicPolicyConfig

      @Stability(Stable) public void setTopicPolicyConfig(@Nullable CfnGuardrail.TopicPolicyConfigProperty value)
      The topic policies to configure for the guardrail.
    • getWordPolicyConfig

      @Stability(Stable) @Nullable public Object getWordPolicyConfig()
      The word policy you configure for the guardrail.
    • setWordPolicyConfig

      @Stability(Stable) public void setWordPolicyConfig(@Nullable IResolvable value)
      The word policy you configure for the guardrail.
    • setWordPolicyConfig

      @Stability(Stable) public void setWordPolicyConfig(@Nullable CfnGuardrail.WordPolicyConfigProperty value)
      The word policy you configure for the guardrail.