Skip to content

Commit d5bdb36

Browse files
authored
chore(guardrails): Add support for input/output modalities in Bedrock guardrails content filter (#1076)
* chore(cdk): upgrade base version to 2.189 and add input output modalities for guardrails
1 parent a49d615 commit d5bdb36

File tree

11 files changed

+112
-21
lines changed

11 files changed

+112
-21
lines changed

.projen/deps.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projenrc.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
const GITHUB_USER = 'awslabs';
3030
const PUBLICATION_NAMESPACE = 'cdklabs';
3131
const PROJECT_NAME = 'generative-ai-cdk-constructs';
32-
const CDK_VERSION: string = '2.188.0';
32+
const CDK_VERSION: string = '2.189.0';
3333

3434
function camelCaseIt(input: string): string {
3535
// Hypens and dashes to spaces and then CamelCase...

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# CDK Generative AI Constructs V0.1.302 (2025-04-11)
2+
3+
Based on CDK library version 2.189.0
4+
15
# CDK Generative AI Constructs V0.1.300 (2025-04-04)
26

37
Based on CDK library version 2.188.0

DEVELOPER_GUIDE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Default output format [None]: json
1616
```
1717

1818
- [Node](https://nodejs.org/en) >= v20.9.0
19-
- [AWS CDK](https://github.com/aws/aws-cdk/releases/tag/v2.188.0) >= 2.188.0
19+
- [AWS CDK](https://github.com/aws/aws-cdk/releases/tag/v2.189.0) >= 2.189.0
2020
- [Python](https://www.python.org/downloads/) >=3.9
2121
- [Projen](https://github.com/projen/projen) >= 0.91.5
2222
- [Yarn](https://classic.yarnpkg.com/lang/en/docs/cli/install/) >= 1.22.19

apidocs/@cdklabs/namespaces/bedrock/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
- [InferenceProfileType](enumerations/InferenceProfileType.md)
3131
- [KnowledgeBaseType](enumerations/KnowledgeBaseType.md)
3232
- [ManagedWordFilterType](enumerations/ManagedWordFilterType.md)
33+
- [ModalityType](enumerations/ModalityType.md)
3334
- [OrchestrationType](enumerations/OrchestrationType.md)
3435
- [ParsingModality](enumerations/ParsingModality.md)
3536
- [ParsingStategyType](enumerations/ParsingStategyType.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[**@cdklabs/generative-ai-cdk-constructs**](../../../../README.md)
2+
3+
***
4+
5+
[@cdklabs/generative-ai-cdk-constructs](../../../../README.md) / [bedrock](../README.md) / ModalityType
6+
7+
# Enumeration: ModalityType
8+
9+
The type of modality that can be used in content filters.
10+
11+
## Enumeration Members
12+
13+
### IMAGE
14+
15+
> **IMAGE**: `"IMAGE"`
16+
17+
Image modality for content filters.
18+
19+
***
20+
21+
### TEXT
22+
23+
> **TEXT**: `"TEXT"`
24+
25+
Text modality for content filters.

apidocs/@cdklabs/namespaces/bedrock/interfaces/ContentFilter.md

+28
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ Interface to declare a content filter.
1010

1111
## Properties
1212

13+
### inputModalities?
14+
15+
> `readonly` `optional` **inputModalities**: [`ModalityType`](../enumerations/ModalityType.md)[]
16+
17+
The input modalities to apply the content filter to.
18+
19+
#### Default
20+
21+
```ts
22+
undefined - Applies to text modality
23+
```
24+
25+
***
26+
1327
### inputStrength
1428

1529
> `readonly` **inputStrength**: [`ContentFilterStrength`](../enumerations/ContentFilterStrength.md)
@@ -18,6 +32,20 @@ The strength of the content filter to apply to prompts / user input.
1832

1933
***
2034

35+
### outputModalities?
36+
37+
> `readonly` `optional` **outputModalities**: [`ModalityType`](../enumerations/ModalityType.md)[]
38+
39+
The output modalities to apply the content filter to.
40+
41+
#### Default
42+
43+
```ts
44+
undefined - Applies to text modality
45+
```
46+
47+
***
48+
2149
### outputStrength
2250

2351
> `readonly` **outputStrength**: [`ContentFilterStrength`](../enumerations/ContentFilterStrength.md)

package.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cdk-lib/bedrock/guardrails/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ guardrail.addContentFilter({
8282
type: ContentFilterType.SEXUAL,
8383
inputStrength: ContentFilterStrength.HIGH,
8484
outputStrength: ContentFilterStrength.MEDIUM,
85+
inputModalities: [ModalityType.TEXT, ModalityType.IMAGE],
86+
outputModalities: [ModalityType.TEXT],
8587
});
8688
```
8789

@@ -92,6 +94,8 @@ guardrail.add_content_filter(
9294
type=ContentFilterType.SEXUAL,
9395
input_strength=ContentFilterStrength.HIGH,
9496
output_strength=ContentFilterStrength.MEDIUM,
97+
input_modalities=[ModalityType.TEXT, ModalityType.IMAGE],
98+
output_modalities=[ModalityType.TEXT],
9599
);
96100
```
97101

@@ -111,6 +115,11 @@ Available content filter strengths:
111115
- `MEDIUM`: Moderate filtering
112116
- `HIGH`: Strict filtering
113117

118+
Available modality types:
119+
120+
- `TEXT`: Text modality for content filters
121+
- `IMAGE`: Image modality for content filters
122+
114123
### Denied Topics
115124

116125
Denied topics allow you to 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.

src/cdk-lib/bedrock/guardrails/guardrail-filters.ts

+24
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ export enum ContentFilterStrength {
2626
HIGH = 'HIGH',
2727
}
2828

29+
/**
30+
* The type of modality that can be used in content filters.
31+
*/
32+
export enum ModalityType {
33+
/**
34+
* Text modality for content filters.
35+
*/
36+
TEXT = 'TEXT',
37+
/**
38+
* Image modality for content filters.
39+
*/
40+
IMAGE = 'IMAGE',
41+
}
42+
2943
/**
3044
* The type of harmful category usable in a content filter.
3145
*/
@@ -82,6 +96,16 @@ export interface ContentFilter {
8296
* The strength of the content filter to apply to model responses.
8397
*/
8498
readonly outputStrength: ContentFilterStrength;
99+
/**
100+
* The input modalities to apply the content filter to.
101+
* @default undefined - Applies to text modality
102+
*/
103+
readonly inputModalities?: ModalityType[];
104+
/**
105+
* The output modalities to apply the content filter to.
106+
* @default undefined - Applies to text modality
107+
*/
108+
readonly outputModalities?: ModalityType[];
85109
}
86110

87111
/******************************************************************************

yarn.lock

+12-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)