Skip to content
v2.278.0

Experimental

@aws-cdk/aws-bedrock-alpha is an experimental (alpha) package: its API may change in any release, without a major version bump.

GuardrailAction Enum ​

Guardrail action when a sensitive entity is detected.

Example ​

ts
const guardrail = new bedrock.Guardrail(this, 'bedrockGuardrails', {
  guardrailName: 'my-BedrockGuardrails',
  // Configure tier for topic filters (optional)
  topicsTierConfig: bedrock.TierConfig.STANDARD,
});

// Use a predefined topic
guardrail.addDeniedTopicFilter(bedrock.Topic.FINANCIAL_ADVICE);

// Create a custom topic with input/output actions
guardrail.addDeniedTopicFilter(
  bedrock.Topic.custom({
    name: 'Legal_Advice',
    definition: 'Offering guidance or suggestions on legal matters, legal actions, interpretation of laws, or legal rights and responsibilities.',
    examples: [
      'Can I sue someone for this?',
      'What are my legal rights in this situation?',
      'Is this action against the law?',
      'What should I do to file a legal complaint?',
      'Can you explain this law to me?',
    ],
    // props below are optional
    inputAction: bedrock.GuardrailAction.BLOCK,
    inputEnabled: true,
    outputAction: bedrock.GuardrailAction.NONE,
    outputEnabled: true,
  })
);
python
guardrail = bedrock.Guardrail(self, "bedrockGuardrails",
    guardrail_name="my-BedrockGuardrails",
    # Configure tier for topic filters (optional)
    topics_tier_config=bedrock.TierConfig.STANDARD
)

# Use a predefined topic
guardrail.add_denied_topic_filter(bedrock.Topic.FINANCIAL_ADVICE)

# Create a custom topic with input/output actions
guardrail.add_denied_topic_filter(
    bedrock.Topic.custom(
        name="Legal_Advice",
        definition="Offering guidance or suggestions on legal matters, legal actions, interpretation of laws, or legal rights and responsibilities.",
        examples=["Can I sue someone for this?", "What are my legal rights in this situation?", "Is this action against the law?", "What should I do to file a legal complaint?", "Can you explain this law to me?"
        ],
        # props below are optional
        input_action=bedrock.GuardrailAction.BLOCK,
        input_enabled=True,
        output_action=bedrock.GuardrailAction.NONE,
        output_enabled=True
    ))
java
Guardrail guardrail = Guardrail.Builder.create(this, "bedrockGuardrails")
        .guardrailName("my-BedrockGuardrails")
        // Configure tier for topic filters (optional)
        .topicsTierConfig(TierConfig.STANDARD)
        .build();

// Use a predefined topic
guardrail.addDeniedTopicFilter(Topic.FINANCIAL_ADVICE);

// Create a custom topic with input/output actions
guardrail.addDeniedTopicFilter(Topic.custom(CustomTopicProps.builder()
        .name("Legal_Advice")
        .definition("Offering guidance or suggestions on legal matters, legal actions, interpretation of laws, or legal rights and responsibilities.")
        .examples(List.of("Can I sue someone for this?", "What are my legal rights in this situation?", "Is this action against the law?", "What should I do to file a legal complaint?", "Can you explain this law to me?"))
        // props below are optional
        .inputAction(GuardrailAction.BLOCK)
        .inputEnabled(true)
        .outputAction(GuardrailAction.NONE)
        .outputEnabled(true)
        .build()));
csharp
// Install: dotnet add package Amazon.CDK.AWS.Bedrock.Alpha
var guardrail = new Guardrail(this, "bedrockGuardrails", new GuardrailProps {
    GuardrailName = "my-BedrockGuardrails",
    // Configure tier for topic filters (optional)
    TopicsTierConfig = TierConfig.STANDARD
});

// Use a predefined topic
guardrail.AddDeniedTopicFilter(Topic.FINANCIAL_ADVICE);

// Create a custom topic with input/output actions
guardrail.AddDeniedTopicFilter(Topic.Custom(new CustomTopicProps {
    Name = "Legal_Advice",
    Definition = "Offering guidance or suggestions on legal matters, legal actions, interpretation of laws, or legal rights and responsibilities.",
    Examples = new [] { "Can I sue someone for this?", "What are my legal rights in this situation?", "Is this action against the law?", "What should I do to file a legal complaint?", "Can you explain this law to me?" },
    // props below are optional
    InputAction = GuardrailAction.BLOCK,
    InputEnabled = true,
    OutputAction = GuardrailAction.NONE,
    OutputEnabled = true
}));
go
// Install: go get github.com/aws/aws-cdk-go/awsbedrockalpha/v2
guardrail := bedrock.NewGuardrail(this, jsii.String("bedrockGuardrails"), &GuardrailProps{
	GuardrailName: jsii.String("my-BedrockGuardrails"),
	// Configure tier for topic filters (optional)
	TopicsTierConfig: bedrock.TierConfig_STANDARD,
})

// Use a predefined topic
guardrail.AddDeniedTopicFilter(bedrock.Topic_FINANCIAL_ADVICE())

// Create a custom topic with input/output actions
guardrail.AddDeniedTopicFilter(bedrock.Topic_Custom(&CustomTopicProps{
	Name: jsii.String("Legal_Advice"),
	Definition: jsii.String("Offering guidance or suggestions on legal matters, legal actions, interpretation of laws, or legal rights and responsibilities."),
	Examples: []*string{
		jsii.String("Can I sue someone for this?"),
		jsii.String("What are my legal rights in this situation?"),
		jsii.String("Is this action against the law?"),
		jsii.String("What should I do to file a legal complaint?"),
		jsii.String("Can you explain this law to me?"),
	},
	// props below are optional
	InputAction: bedrock.GuardrailAction_BLOCK,
	InputEnabled: jsii.Boolean(true),
	OutputAction: bedrock.GuardrailAction_NONE,
	OutputEnabled: jsii.Boolean(true),
}))

Members ​

MemberDescription
BLOCKIf sensitive information is detected in the prompt or response, the guardrail blocks all the content and returns a message that you configure.
ANONYMIZEIf sensitive information is detected in the model response, the guardrail masks it with an identifier, the sensitive information is masked and replaced with identifier tags (for example: [NAME-1], [NAME-2], [EMAIL-1], etc.).
NONEDo not take any action.

Referenced by ​

  • ContentFilter.inputActioninput_actioninputActionInputActionInputAction
  • ContentFilter.outputActionoutput_actionoutputActionOutputActionOutputAction
  • ContextualGroundingFilter.actionactionactionActionAction
  • CustomTopicProps.inputActioninput_actioninputActionInputActionInputAction
  • CustomTopicProps.outputActionoutput_actionoutputActionOutputActionOutputAction
  • ManagedWordFilter.inputActioninput_actioninputActionInputActionInputAction
  • ManagedWordFilter.outputActionoutput_actionoutputActionOutputActionOutputAction
  • PIIFilter.actionactionactionActionAction
  • PIIFilter.inputActioninput_actioninputActionInputActionInputAction
  • PIIFilter.outputActionoutput_actionoutputActionOutputActionOutputAction
  • RegexFilter.actionactionactionActionAction
  • RegexFilter.inputActioninput_actioninputActionInputActionInputAction
  • RegexFilter.outputActionoutput_actionoutputActionOutputActionOutputAction
  • Topic.inputActioninput_actioninputActionInputActionInputAction
  • Topic.outputActionoutput_actionoutputActionOutputActionOutputAction
  • WordFilter.inputActioninput_actioninputActionInputActionInputAction
  • WordFilter.outputActionoutput_actionoutputActionOutputActionOutputAction