Experimental
@aws-cdk/aws-bedrock-alpha is an experimental (alpha) package: its API may change in any release, without a major version bump.
CustomTopicProps Struct
Interface for creating a custom Topic.
| 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
Provide a clear definition to detect and block user inputs and FM responses that fall into this topic.
Avoid starting with "don't".
example
ts
`Investment advice refers to inquiries, guidance, or recommendations
regarding the management or allocation of funds or assets with the goal of
generating returns or achieving specific financial objectives.`
examplesstring[]examplestyping.List[str]examplesList<String>Examplesstring[]Examples*[]*string required #Representative phrases that refer to the topic.
These phrases can represent a user input or a model response. Add between 1 and 100 phrases, up to 100 characters each.
example
ts
"Where should I invest my money?"
inputActionoptionalGuardrailActioninput_actionoptionalGuardrailActioninputActionoptionalGuardrailActionInputActionoptionalGuardrailActionInputActionoptionalGuardrailAction = GuardrailAction.BLOCK #The action to take when a topic is detected in the input.
inputEnabledoptionalbooleaninput_enabledoptionalboolinputEnabledoptionalBooleanInputEnabledoptionalboolInputEnabledoptional*bool = true #Whether the topic filter is enabled for input.
The name of the topic to deny.
outputActionoptionalGuardrailActionoutput_actionoptionalGuardrailActionoutputActionoptionalGuardrailActionOutputActionoptionalGuardrailActionOutputActionoptionalGuardrailAction = GuardrailAction.BLOCK #The action to take when a topic is detected in the output.
outputEnabledoptionalbooleanoutput_enabledoptionalbooloutputEnabledoptionalBooleanOutputEnabledoptionalboolOutputEnabledoptional*bool = true #Whether the topic filter is enabled for output.