Experimental
@aws-cdk/aws-bedrock-alpha is an experimental (alpha) package: its API may change in any release, without a major version bump.
Topic Class
Represents predefined topics that can be used to filter content.
| Stability | Experimental |
|---|---|
| Source | bedrock/guardrails/guardrail-filters.ts |
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),
}))
Properties
Definition of the topic.
examplesmay be undefinedstring[]examplesmay be undefinedtyping.List[str]examplesmay be undefinedList<String>Examplesmay be undefinedstring[]Examplesmay be undefined*[]*string #Representative phrases that refer to the topic.
FINANCIAL_ADVICETopicFINANCIAL_ADVICETopicFINANCIAL_ADVICETopicFINANCIAL_ADVICETopicFINANCIAL_ADVICETopic static #Filter for financial advice and investment recommendations.
INAPPROPRIATE_CONTENTTopicINAPPROPRIATE_CONTENTTopicINAPPROPRIATE_CONTENTTopicINAPPROPRIATE_CONTENTTopicINAPPROPRIATE_CONTENTTopic static #Filter for inappropriate or explicit content.
inputActionmay be undefinedGuardrailActioninput_actionmay be undefinedGuardrailActioninputActionmay be undefinedGuardrailActionInputActionmay be undefinedGuardrailActionInputActionmay be undefinedGuardrailAction = GuardrailAction.BLOCK #The action to take when a topic is detected in the input.
inputEnabledmay be undefinedbooleaninput_enabledmay be undefinedboolinputEnabledmay be undefinedBooleanInputEnabledmay be undefinedboolInputEnabledmay be undefined*bool = true #Whether the topic filter is enabled for input.
Filter for legal advice and recommendations.
MEDICAL_ADVICETopicMEDICAL_ADVICETopicMEDICAL_ADVICETopicMEDICAL_ADVICETopicMEDICAL_ADVICETopic static #Filter for medical advice and health recommendations.
The name of the topic to deny.
outputActionmay be undefinedGuardrailActionoutput_actionmay be undefinedGuardrailActionoutputActionmay be undefinedGuardrailActionOutputActionmay be undefinedGuardrailActionOutputActionmay be undefinedGuardrailAction = GuardrailAction.BLOCK #The action to take when a topic is detected in the output.
outputEnabledmay be undefinedbooleanoutput_enabledmay be undefinedbooloutputEnabledmay be undefinedBooleanOutputEnabledmay be undefinedboolOutputEnabledmay be undefined*bool = true #Whether the topic filter is enabled for output.
Methods
custom(props: CustomTopicProps): Topic // chainable@staticmethod def custom(props: CustomTopicProps) -> Topicpublic static Topic custom(CustomTopicProps props)public static Topic Custom(CustomTopicProps props)func Custom(Props CustomTopicProps) Topic static #Create a custom topic filter.
1 parameter
Parameters
propspropspropspropsProps— Properties for the custom topic filter.