class Guardrail (construct)
Language | Type name |
---|---|
![]() | Amazon.CDK.AWS.Bedrock.Alpha.Guardrail |
![]() | github.com/aws/aws-cdk-go/awsbedrockalpha/v2#Guardrail |
![]() | software.amazon.awscdk.services.bedrock.alpha.Guardrail |
![]() | aws_cdk.aws_bedrock_alpha.Guardrail |
![]() | @aws-cdk/aws-bedrock-alpha ยป Guardrail |
Implements
IConstruct
, IDependable
, IResource
, IGuardrail
Class to create a Guardrail with CDK.
Example
const guardrail = new bedrock.Guardrail(this, 'bedrockGuardrails', {
guardrailName: 'my-BedrockGuardrails',
});
// Add regex filter with input/output actions
guardrail.addRegexFilter({
name: 'TestRegexFilter',
pattern: 'test-pattern',
action: bedrock.GuardrailAction.ANONYMIZE,
// below props are optional
description: 'This is a test regex filter',
inputAction: bedrock.GuardrailAction.BLOCK,
inputEnabled: true,
outputAction: bedrock.GuardrailAction.ANONYMIZE,
outputEnabled: true,
});
Initializer
new Guardrail(scope: Construct, id: string, props: GuardrailProps)
Parameters
- scope
Construct
- id
string
- props
Guardrail
Props
Construct Props
Name | Type | Description |
---|---|---|
guardrail | string | The name of the guardrail. |
blocked | string | The message to return when the guardrail blocks a prompt. |
blocked | string | The message to return when the guardrail blocks a model response. |
content | Content [] | The content filters to apply to the guardrail. |
content | Tier | The tier configuration to apply to the guardrail. |
contextual | Contextual [] | The contextual grounding filters to apply to the guardrail. |
cross | Guardrail | The cross-region configuration for the guardrail. |
denied | Topic [] | A list of policies related to topics that the guardrail should deny. |
description? | string | The description of the guardrail. |
kms | IKey | A custom KMS key to use for encrypting data. |
managed | Managed [] | The managed word filters to apply to the guardrail. |
pii | PIIFilter [] | The PII filters to apply to the guardrail. |
regex | Regex [] | The regular expression (regex) filters to apply to the guardrail. |
topics | Tier | The tier configuration to apply to the guardrail. |
word | Word [] | The word filters to apply to the guardrail. |
guardrailName
Type:
string
The name of the guardrail.
This will be used as the physical name of the guardrail.
blockedInputMessaging?
Type:
string
(optional, default: "Sorry, your query violates our usage policy.")
The message to return when the guardrail blocks a prompt.
Must be between 1 and 500 characters.
blockedOutputsMessaging?
Type:
string
(optional, default: "Sorry, I am unable to answer your question because of our usage policy.")
The message to return when the guardrail blocks a model response.
Must be between 1 and 500 characters.
contentFilters?
Type:
Content
[]
(optional, default: [])
The content filters to apply to the guardrail.
contentFiltersTierConfig?
Type:
Tier
(optional, default: filters.TierConfig.CLASSIC)
The tier configuration to apply to the guardrail.
contextualGroundingFilters?
Type:
Contextual
[]
(optional, default: [])
The contextual grounding filters to apply to the guardrail.
crossRegionConfig?
Type:
Guardrail
(optional, default: No cross-region configuration)
The cross-region configuration for the guardrail.
This is optional and when provided, it should be of type GuardrailCrossRegionConfigProperty.
deniedTopics?
Type:
Topic
[]
(optional, default: [])
A list of policies related to topics that the guardrail should deny.
description?
Type:
string
(optional, default: No description)
The description of the guardrail.
kmsKey?
Type:
IKey
(optional, default: Data is encrypted by default with a key that AWS owns and manages for you)
A custom KMS key to use for encrypting data.
managedWordListFilters?
Type:
Managed
[]
(optional, default: [])
The managed word filters to apply to the guardrail.
piiFilters?
Type:
PIIFilter
[]
(optional, default: [])
The PII filters to apply to the guardrail.
regexFilters?
Type:
Regex
[]
(optional, default: [])
The regular expression (regex) filters to apply to the guardrail.
topicsTierConfig?
Type:
Tier
(optional, default: filters.TierConfig.CLASSIC)
The tier configuration to apply to the guardrail.
wordFilters?
Type:
Word
[]
(optional, default: [])
The word filters to apply to the guardrail.
Properties
Name | Type | Description |
---|---|---|
blocked | string | The message to return when the guardrail blocks a prompt. |
blocked | string | The message to return when the guardrail blocks a model response. |
content | Content [] | The content filters applied by the guardrail. |
content | Tier | The tier that your guardrail uses for content filters. |
contextual | Contextual [] | The contextual grounding filters applied by the guardrail. |
denied | Topic [] | The denied topic filters applied by the guardrail. |
env | Resource | The environment this resource belongs to. |
guardrail | string | The ARN of the guardrail. |
guardrail | string | The ID of the guardrail. |
guardrail | string | The version of the guardrail. |
hash | string | The computed hash of the guardrail properties. |
managed | Managed [] | The managed word list filters applied by the guardrail. |
name | string | The name of the guardrail. |
node | Node | The tree node. |
pii | PIIFilter [] | The PII filters applied by the guardrail. |
regex | Regex [] | The regex filters applied by the guardrail. |
stack | Stack | The stack in which this resource is defined. |
topics | Tier | The tier that your guardrail uses for denied topic filters. |
word | Word [] | The word filters applied by the guardrail. |
cross | Guardrail | The cross-region configuration for the guardrail. |
kms | IKey | The KMS key used to encrypt data. |
last | string | When this guardrail was last updated. |
static PROPERTY_INJECTION_ID | string | Uniquely identifies this class. |
blockedInputMessaging
Type:
string
The message to return when the guardrail blocks a prompt.
blockedOutputsMessaging
Type:
string
The message to return when the guardrail blocks a model response.
contentFilters
Type:
Content
[]
The content filters applied by the guardrail.
contentFiltersTierConfig
Type:
Tier
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.
contextualGroundingFilters
Type:
Contextual
[]
The contextual grounding filters applied by the guardrail.
deniedTopics
Type:
Topic
[]
The denied topic filters applied by the guardrail.
env
Type:
Resource
The environment this resource belongs to.
For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.
guardrailArn
Type:
string
The ARN of the guardrail.
guardrailId
Type:
string
The ID of the guardrail.
guardrailVersion
Type:
string
The version of the guardrail.
hash
Type:
string
The computed hash of the guardrail properties.
managedWordListFilters
Type:
Managed
[]
The managed word list filters applied by the guardrail.
name
Type:
string
The name of the guardrail.
node
Type:
Node
The tree node.
piiFilters
Type:
PIIFilter
[]
The PII filters applied by the guardrail.
regexFilters
Type:
Regex
[]
The regex filters applied by the guardrail.
stack
Type:
Stack
The stack in which this resource is defined.
topicsTierConfig
Type:
Tier
The tier that your guardrail uses for denied topic filters.
wordFilters
Type:
Word
[]
The word filters applied by the guardrail.
crossRegionConfig?
Type:
Guardrail
(optional)
The cross-region configuration for the guardrail.
kmsKey?
Type:
IKey
(optional, default: undefined - "Data is encrypted by default with a key that AWS owns and manages for you")
The KMS key used to encrypt data.
lastUpdated?
Type:
string
(optional)
When this guardrail was last updated.
static PROPERTY_INJECTION_ID
Type:
string
Uniquely identifies this class.
Methods
Name | Description |
---|---|
add | Adds a content filter to the guardrail. |
add | Adds a contextual grounding filter to the guardrail. |
add | Adds a denied topic filter to the guardrail. |
add | Adds a managed word list filter to the guardrail. |
add | Adds a PII filter to the guardrail. |
add | Adds a regex filter to the guardrail. |
add | Adds a word filter to the guardrail. |
add | Adds a word filter to the guardrail. |
apply | Apply the given removal policy to this resource. |
create | Create a version for the guardrail. |
grant(grantee, ...actions) | Grant the given principal identity permissions to perform actions on this guardrail. |
grant | Grant the given identity permissions to apply the guardrail. |
metric(metricName, props?) | Return the given named metric for this guardrail. |
metric | Return the invocation client errors metric for this guardrail. |
metric | Return the invocation latency metric for this guardrail. |
metric | Return the invocation server errors metric for this guardrail. |
metric | Return the invocation throttles metric for this guardrail. |
metric | Return the invocations metric for this guardrail. |
metric | Return the invocations intervened metric for this guardrail. |
metric | Return the text unit count metric for this guardrail. |
to | Returns a string representation of this construct. |
static from | Import a low-level L1 Cfn Guardrail. |
static from | Import a guardrail given its attributes. |
addContentFilter(filter)
public addContentFilter(filter: ContentFilter): void
Parameters
- filter
Content
โ The content filter to add.Filter
Adds a content filter to the guardrail.
addContextualGroundingFilter(filter)
public addContextualGroundingFilter(filter: ContextualGroundingFilter): void
Parameters
- filter
Contextual
โ The contextual grounding filter to add.Grounding Filter
Adds a contextual grounding filter to the guardrail.
addDeniedTopicFilter(filter)
public addDeniedTopicFilter(filter: Topic): void
Parameters
- filter
Topic
โ The denied topic filter to add.
Adds a denied topic filter to the guardrail.
addManagedWordListFilter(filter)
public addManagedWordListFilter(filter: ManagedWordFilter): void
Parameters
- filter
Managed
โ The managed word list filter to add.Word Filter
Adds a managed word list filter to the guardrail.
addPIIFilter(filter)
public addPIIFilter(filter: PIIFilter): void
Parameters
- filter
PIIFilter
โ The PII filter to add.
Adds a PII filter to the guardrail.
addRegexFilter(filter)
public addRegexFilter(filter: RegexFilter): void
Parameters
- filter
Regex
โ The regex filter to add.Filter
Adds a regex filter to the guardrail.
addWordFilter(filter)
public addWordFilter(filter: WordFilter): void
Parameters
- filter
Word
โ The word filter to add.Filter
Adds a word filter to the guardrail.
addWordFilterFromFile(filePath, inputAction?, outputAction?, inputEnabled?, outputEnabled?)
public addWordFilterFromFile(filePath: string, inputAction?: GuardrailAction, outputAction?: GuardrailAction, inputEnabled?: boolean, outputEnabled?: boolean): void
Parameters
- filePath
string
โ The location of the word filter file. - inputAction
Guardrail
Action - outputAction
Guardrail
Action - inputEnabled
boolean
- outputEnabled
boolean
Adds a word filter to the guardrail.
applyRemovalPolicy(policy)
public applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
Policy
Apply the given removal policy to this resource.
The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.
The resource can be deleted (RemovalPolicy.DESTROY
), or left in your AWS
account for data recovery and cleanup later (RemovalPolicy.RETAIN
).
createVersion(description?)
public createVersion(description?: string): string
Parameters
- description
string
โ The description of the version.
Returns
string
Create a version for the guardrail.
grant(grantee, ...actions)
public grant(grantee: IGrantable, ...actions: string[]): Grant
Parameters
- grantee
IGrantable
- actions
string
Returns
Grant the given principal identity permissions to perform actions on this guardrail.
grantApply(grantee)
public grantApply(grantee: IGrantable): Grant
Parameters
- grantee
IGrantable
Returns
Grant the given identity permissions to apply the guardrail.
metric(metricName, props?)
public metric(metricName: string, props?: MetricOptions): Metric
Parameters
- metricName
string
- props
Metric
Options
Returns
Return the given named metric for this guardrail.
By default, the metric will be calculated as a sum over a period of 5 minutes.
You can customize this by using the statistic
and period
properties.
metricInvocationClientErrors(props?)
public metricInvocationClientErrors(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
Return the invocation client errors metric for this guardrail.
metricInvocationLatency(props?)
public metricInvocationLatency(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
Return the invocation latency metric for this guardrail.
metricInvocationServerErrors(props?)
public metricInvocationServerErrors(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
Return the invocation server errors metric for this guardrail.
metricInvocationThrottles(props?)
public metricInvocationThrottles(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
Return the invocation throttles metric for this guardrail.
metricInvocations(props?)
public metricInvocations(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
Return the invocations metric for this guardrail.
metricInvocationsIntervened(props?)
public metricInvocationsIntervened(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
Return the invocations intervened metric for this guardrail.
metricTextUnitCount(props?)
public metricTextUnitCount(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
Return the text unit count metric for this guardrail.
toString()
public toString(): string
Returns
string
Returns a string representation of this construct.
static fromCfnGuardrail(cfnGuardrail)
public static fromCfnGuardrail(cfnGuardrail: CfnGuardrail): IGuardrail
Parameters
- cfnGuardrail
Cfn
Guardrail
Returns
Import a low-level L1 Cfn Guardrail.
static fromGuardrailAttributes(scope, id, attrs)
public static fromGuardrailAttributes(scope: Construct, id: string, attrs: GuardrailAttributes): IGuardrail
Parameters
- scope
Construct
- id
string
- attrs
Guardrail
Attributes
Returns
Import a guardrail given its attributes.