konokenj.cdk-api-mcp-server 0.41.0__py3-none-any.whl → 0.43.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of konokenj.cdk-api-mcp-server might be problematic. Click here for more details.
- cdk_api_mcp_server/__about__.py +1 -1
- cdk_api_mcp_server/resources/aws-cdk/constructs/@aws-cdk/aws-bedrock-alpha/README.md +540 -0
- cdk_api_mcp_server/resources/aws-cdk/constructs/@aws-cdk/aws-eks-v2-alpha/README.md +44 -46
- cdk_api_mcp_server/resources/aws-cdk/constructs/@aws-cdk/aws-glue-alpha/README.md +9 -9
- cdk_api_mcp_server/resources/aws-cdk/constructs/@aws-cdk/aws-lambda-python-alpha/README.md +6 -6
- cdk_api_mcp_server/resources/aws-cdk/constructs/@aws-cdk/aws-s3tables-alpha/README.md +28 -1
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-apigatewayv2/integ.api-dualstack.ts +3 -4
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-apigatewayv2/integ.api.ts +2 -4
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-apigatewayv2/integ.stage.ts +7 -20
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-apigatewayv2-authorizers/integ.iam.ts +34 -38
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-apigatewayv2-integrations/integ.sqs.ts +58 -71
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-certificatemanager/README.md +11 -0
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-cloudwatch/README.md +13 -0
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-cloudwatch/integ.dashboard-with-graphwidget-with-labels-visible.ts +92 -0
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-codepipeline-actions/integ.pipeline-elastic-beanstalk-deploy.ts +1 -1
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-cognito/README.md +11 -0
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-cognito/integ.user-pool-client-explicit-props.ts +1 -0
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-dynamodb/README.md +38 -13
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-dynamodb/integ.dynamodb-v2.cci.ts +49 -0
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-dynamodb/integ.dynamodb.cci.ts +27 -0
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-dynamodb/integ.dynamodb.contirubtor-insights-for-gsi.ts +6 -2
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-dynamodb/integ.table-v2-global.ts +9 -3
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-ecs/README.md +3 -0
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-ecs/integ.ebs-volume-initialization-rate.ts +80 -0
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-ecs-patterns/README.md +2 -0
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-ecs-patterns/integ.alb-fargate-service-smart-defaults.ts +143 -0
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-events/README.md +25 -3
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-events/integ.archive-customer-managed-key.ts +23 -0
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-events-targets/README.md +64 -2
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-rds/README.md +18 -0
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-rds/integ.cluster.ts +1 -1
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-s3-assets/integ.assets.bundling.docker-opts.ts +4 -1
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-s3-deployment/README.md +18 -0
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-sns/README.md +2 -0
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-sns-subscriptions/integ.sns-sqs-subscription-filter.ts +75 -0
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-sns-subscriptions/integ.sns-sqs.ts +21 -40
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-stepfunctions-tasks/integ.evaluate-expression-nodejs22.ts +27 -0
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-stepfunctions-tasks/integ.invoke-jsonata.ts +87 -80
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-stepfunctions-tasks/integ.invoke.ts +87 -69
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-stepfunctions-tasks/integ.start-job-run.ts +102 -104
- cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/cx-api/FEATURE_FLAGS.md +28 -1
- {konokenj_cdk_api_mcp_server-0.41.0.dist-info → konokenj_cdk_api_mcp_server-0.43.0.dist-info}/METADATA +2 -2
- {konokenj_cdk_api_mcp_server-0.41.0.dist-info → konokenj_cdk_api_mcp_server-0.43.0.dist-info}/RECORD +46 -38
- {konokenj_cdk_api_mcp_server-0.41.0.dist-info → konokenj_cdk_api_mcp_server-0.43.0.dist-info}/WHEEL +0 -0
- {konokenj_cdk_api_mcp_server-0.41.0.dist-info → konokenj_cdk_api_mcp_server-0.43.0.dist-info}/entry_points.txt +0 -0
- {konokenj_cdk_api_mcp_server-0.41.0.dist-info → konokenj_cdk_api_mcp_server-0.43.0.dist-info}/licenses/LICENSE.txt +0 -0
cdk_api_mcp_server/__about__.py
CHANGED
|
@@ -35,6 +35,20 @@ This construct library facilitates the deployment of Bedrock Agents, enabling yo
|
|
|
35
35
|
- [Agent Collaboration](#agent-collaboration)
|
|
36
36
|
- [Custom Orchestration](#custom-orchestration)
|
|
37
37
|
- [Agent Alias](#agent-alias)
|
|
38
|
+
- [Guardrails](#guardrails)
|
|
39
|
+
- [Guardrail Properties](#guardrail-properties)
|
|
40
|
+
- [Filter Types](#filter-types)
|
|
41
|
+
- [Content Filters](#content-filters)
|
|
42
|
+
- [Denied Topics](#denied-topics)
|
|
43
|
+
- [Word Filters](#word-filters)
|
|
44
|
+
- [PII Filters](#pii-filters)
|
|
45
|
+
- [Regex Filters](#regex-filters)
|
|
46
|
+
- [Contextual Grounding Filters](#contextual-grounding-filters)
|
|
47
|
+
- [Guardrail Methods](#guardrail-methods)
|
|
48
|
+
- [Guardrail Permissions](#guardrail-permissions)
|
|
49
|
+
- [Guardrail Metrics](#guardrail-metrics)
|
|
50
|
+
- [Importing Guardrails](#importing-guardrails)
|
|
51
|
+
- [Guardrail Versioning](#guardrail-versioning)
|
|
38
52
|
- [Prompts](#prompts)
|
|
39
53
|
- [Prompt Variants](#prompt-variants)
|
|
40
54
|
- [Basic Text Prompt](#basic-text-prompt)
|
|
@@ -66,6 +80,29 @@ const agent = new bedrock.Agent(this, 'Agent', {
|
|
|
66
80
|
});
|
|
67
81
|
```
|
|
68
82
|
|
|
83
|
+
You can also create an agent with a guardrail:
|
|
84
|
+
|
|
85
|
+
```ts fixture=default
|
|
86
|
+
// Create a guardrail to filter inappropriate content
|
|
87
|
+
const guardrail = new bedrock.Guardrail(this, 'bedrockGuardrails', {
|
|
88
|
+
guardrailName: 'my-BedrockGuardrails',
|
|
89
|
+
description: 'Legal ethical guardrails.',
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
guardrail.addContentFilter({
|
|
93
|
+
type: bedrock.ContentFilterType.SEXUAL,
|
|
94
|
+
inputStrength: bedrock.ContentFilterStrength.HIGH,
|
|
95
|
+
outputStrength: bedrock.ContentFilterStrength.MEDIUM,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// Create an agent with the guardrail
|
|
99
|
+
const agentWithGuardrail = new bedrock.Agent(this, 'AgentWithGuardrail', {
|
|
100
|
+
foundationModel: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
|
|
101
|
+
instruction: 'You are a helpful and friendly agent that answers questions about literature.',
|
|
102
|
+
guardrail: guardrail,
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
69
106
|
### Agent Properties
|
|
70
107
|
|
|
71
108
|
The Bedrock Agent class supports the following properties.
|
|
@@ -81,6 +118,8 @@ The Bedrock Agent class supports the following properties.
|
|
|
81
118
|
| kmsKey | kms.IKey | No | The KMS key of the agent if custom encryption is configured. Defaults to AWS managed key |
|
|
82
119
|
| description | string | No | A description of the agent. Defaults to no description |
|
|
83
120
|
| actionGroups | AgentActionGroup[] | No | The Action Groups associated with the agent |
|
|
121
|
+
| guardrail | IGuardrail | No | The guardrail that will be associated with the agent. Defaults to no guardrail |
|
|
122
|
+
| memory | Memory | No | The type and configuration of the memory to maintain context across multiple sessions and recall past interactions. Defaults to no memory |
|
|
84
123
|
| promptOverrideConfiguration | PromptOverrideConfiguration | No | Overrides some prompt templates in different parts of an agent sequence configuration |
|
|
85
124
|
| userInputEnabled | boolean | No | Select whether the agent can prompt additional information from the user when it lacks enough information. Defaults to false |
|
|
86
125
|
| codeInterpreterEnabled | boolean | No | Select whether the agent can generate, run, and troubleshoot code when trying to complete a task. Defaults to false |
|
|
@@ -621,6 +660,507 @@ const agentAlias = new bedrock.AgentAlias(this, 'myAlias', {
|
|
|
621
660
|
});
|
|
622
661
|
```
|
|
623
662
|
|
|
663
|
+
## Guardrails
|
|
664
|
+
|
|
665
|
+
Amazon Bedrock's Guardrails feature enables you to implement robust governance and control mechanisms for your generative AI applications, ensuring alignment with your specific use cases and responsible AI policies. Guardrails empowers you to create multiple tailored policy configurations, each designed to address the unique requirements and constraints of different use cases. These policy configurations can then be seamlessly applied across multiple foundation models (FMs) and Agents, ensuring a consistent user experience and standardizing safety, security, and privacy controls throughout your generative AI ecosystem.
|
|
666
|
+
|
|
667
|
+
With Guardrails, you can define and enforce granular, customizable policies to precisely govern the behavior of your generative AI applications. You can configure the following policies in a guardrail to avoid undesirable and harmful content and remove sensitive information for privacy protection.
|
|
668
|
+
|
|
669
|
+
Content filters – Adjust filter strengths to block input prompts or model responses containing harmful content.
|
|
670
|
+
Denied topics – 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.
|
|
671
|
+
Word filters – Configure filters to block undesirable words, phrases, and profanity. Such words can include offensive terms, competitor names etc.
|
|
672
|
+
Sensitive information filters – Block or mask sensitive information such as personally identifiable information (PII) or custom regex in user inputs and model responses.
|
|
673
|
+
You can create a Guardrail with a minimum blockedInputMessaging, blockedOutputsMessaging and default content filter policy.
|
|
674
|
+
|
|
675
|
+
### Basic Guardrail Creation
|
|
676
|
+
|
|
677
|
+
#### TypeScript
|
|
678
|
+
|
|
679
|
+
```ts fixture=default
|
|
680
|
+
const guardrail = new bedrock.Guardrail(this, 'bedrockGuardrails', {
|
|
681
|
+
guardrailName: 'my-BedrockGuardrails',
|
|
682
|
+
description: 'Legal ethical guardrails.',
|
|
683
|
+
});
|
|
684
|
+
|
|
685
|
+
// add at least one policy for the guardrail
|
|
686
|
+
```
|
|
687
|
+
|
|
688
|
+
### Guardrail Properties
|
|
689
|
+
|
|
690
|
+
| Property | Type | Required | Description |
|
|
691
|
+
|----------|------|----------|-------------|
|
|
692
|
+
| guardrailName | string | Yes | The name of the guardrail |
|
|
693
|
+
| description | string | No | The description of the guardrail |
|
|
694
|
+
| blockedInputMessaging | string | No | The message to return when the guardrail blocks a prompt. Default: "Sorry, your query violates our usage policy." |
|
|
695
|
+
| blockedOutputsMessaging | string | No | The message to return when the guardrail blocks a model response. Default: "Sorry, I am unable to answer your question because of our usage policy." |
|
|
696
|
+
| kmsKey | IKey | No | A custom KMS key to use for encrypting data. Default: Your data is encrypted by default with a key that AWS owns and manages for you. |
|
|
697
|
+
| crossRegionConfig | GuardrailCrossRegionConfigProperty | No | The cross-region configuration for the guardrail. This enables cross-region inference for enhanced language support and filtering capabilities. Default: No cross-region configuration |
|
|
698
|
+
| contentFilters | ContentFilter[] | No | The content filters to apply to the guardrail |
|
|
699
|
+
| contentFiltersTierConfig | TierConfig | No | The tier configuration to apply to content filters. Default: TierConfig.CLASSIC |
|
|
700
|
+
| deniedTopics | Topic[] | No | Up to 30 denied topics to block user inputs or model responses associated with the topic |
|
|
701
|
+
| topicsTierConfig | TierConfig | No | The tier configuration to apply to topic filters. Default: TierConfig.CLASSIC |
|
|
702
|
+
| wordFilters | string[] | No | The word filters to apply to the guardrail |
|
|
703
|
+
| managedWordListFilters | ManagedWordFilterType[] | No | The managed word filters to apply to the guardrail |
|
|
704
|
+
| piiFilters | PIIFilter[] | No | The PII filters to apply to the guardrail |
|
|
705
|
+
| regexFilters | RegexFilter[] | No | The regular expression (regex) filters to apply to the guardrail |
|
|
706
|
+
| contextualGroundingFilters | ContextualGroundingFilter[] | No | The contextual grounding filters to apply to the guardrail |
|
|
707
|
+
|
|
708
|
+
### Filter Types
|
|
709
|
+
|
|
710
|
+
#### Content Filters
|
|
711
|
+
|
|
712
|
+
Content filters allow you to block input prompts or model responses containing harmful content. You can adjust the filter strength and configure separate actions for input and output.
|
|
713
|
+
|
|
714
|
+
##### Content Filter Configuration
|
|
715
|
+
|
|
716
|
+
```ts fixture=default
|
|
717
|
+
const guardrail = new bedrock.Guardrail(this, 'bedrockGuardrails', {
|
|
718
|
+
guardrailName: 'my-BedrockGuardrails',
|
|
719
|
+
// Configure tier for content filters (optional)
|
|
720
|
+
contentFiltersTierConfig: bedrock.TierConfig.STANDARD,
|
|
721
|
+
});
|
|
722
|
+
|
|
723
|
+
guardrail.addContentFilter({
|
|
724
|
+
type: bedrock.ContentFilterType.SEXUAL,
|
|
725
|
+
inputStrength: bedrock.ContentFilterStrength.HIGH,
|
|
726
|
+
outputStrength: bedrock.ContentFilterStrength.MEDIUM,
|
|
727
|
+
// props below are optional
|
|
728
|
+
inputAction: bedrock.GuardrailAction.BLOCK,
|
|
729
|
+
inputEnabled: true,
|
|
730
|
+
outputAction: bedrock.GuardrailAction.NONE,
|
|
731
|
+
outputEnabled: true,
|
|
732
|
+
inputModalities: [bedrock.ModalityType.TEXT, bedrock.ModalityType.IMAGE],
|
|
733
|
+
outputModalities: [bedrock.ModalityType.TEXT],
|
|
734
|
+
});
|
|
735
|
+
```
|
|
736
|
+
|
|
737
|
+
Available content filter types:
|
|
738
|
+
|
|
739
|
+
- `SEXUAL`: Describes input prompts and model responses that indicates sexual interest, activity, or arousal
|
|
740
|
+
- `VIOLENCE`: Describes input prompts and model responses that includes glorification of or threats to inflict physical pain
|
|
741
|
+
- `HATE`: Describes input prompts and model responses that discriminate, criticize, insult, denounce, or dehumanize a person or group
|
|
742
|
+
- `INSULTS`: Describes input prompts and model responses that includes demeaning, humiliating, mocking, insulting, or belittling language
|
|
743
|
+
- `MISCONDUCT`: Describes input prompts and model responses that seeks or provides information about engaging in misconduct activity
|
|
744
|
+
- `PROMPT_ATTACK`: Enable to detect and block user inputs attempting to override system instructions
|
|
745
|
+
|
|
746
|
+
Available content filter strengths:
|
|
747
|
+
|
|
748
|
+
- `NONE`: No filtering
|
|
749
|
+
- `LOW`: Light filtering
|
|
750
|
+
- `MEDIUM`: Moderate filtering
|
|
751
|
+
- `HIGH`: Strict filtering
|
|
752
|
+
|
|
753
|
+
Available guardrail actions:
|
|
754
|
+
|
|
755
|
+
- `BLOCK`: Blocks the content from being processed
|
|
756
|
+
- `ANONYMIZE`: Masks the content with an identifier tag
|
|
757
|
+
- `NONE`: Takes no action
|
|
758
|
+
|
|
759
|
+
> Warning: the ANONYMIZE action is not available in all configurations. Please refer to the documentation of each filter to see which ones
|
|
760
|
+
> support
|
|
761
|
+
|
|
762
|
+
Available modality types:
|
|
763
|
+
|
|
764
|
+
- `TEXT`: Text modality for content filters
|
|
765
|
+
- `IMAGE`: Image modality for content filters
|
|
766
|
+
|
|
767
|
+
#### Tier Configuration
|
|
768
|
+
|
|
769
|
+
Guardrails support tier configurations that determine the level of language support and robustness for content and topic filters. You can configure separate tier settings for content filters and topic filters.
|
|
770
|
+
|
|
771
|
+
##### Tier Configuration Options
|
|
772
|
+
|
|
773
|
+
```ts fixture=default
|
|
774
|
+
const guardrail = new bedrock.Guardrail(this, 'bedrockGuardrails', {
|
|
775
|
+
guardrailName: 'my-BedrockGuardrails',
|
|
776
|
+
// Configure tier for content filters
|
|
777
|
+
contentFiltersTierConfig: bedrock.TierConfig.STANDARD,
|
|
778
|
+
// Configure tier for topic filters
|
|
779
|
+
topicsTierConfig: bedrock.TierConfig.CLASSIC,
|
|
780
|
+
});
|
|
781
|
+
```
|
|
782
|
+
|
|
783
|
+
Available tier configurations:
|
|
784
|
+
|
|
785
|
+
- `CLASSIC`: Provides established guardrails functionality supporting English, French, and Spanish languages
|
|
786
|
+
- `STANDARD`: Provides a more robust solution than the CLASSIC tier and has more comprehensive language support. This tier requires that your guardrail use cross-Region inference
|
|
787
|
+
|
|
788
|
+
> Note: The STANDARD tier provides enhanced language support and more comprehensive filtering capabilities, but requires cross-Region inference to be enabled for your guardrail.
|
|
789
|
+
|
|
790
|
+
#### Cross-Region Configuration
|
|
791
|
+
|
|
792
|
+
You can configure a system-defined guardrail profile to use with your guardrail. Guardrail profiles define the destination AWS Regions where guardrail inference requests can be automatically routed. Using guardrail profiles helps maintain guardrail performance and reliability when demand increases.
|
|
793
|
+
|
|
794
|
+
##### Cross-Region Configuration Properties
|
|
795
|
+
|
|
796
|
+
| Property | Type | Required | Description |
|
|
797
|
+
|----------|------|----------|-------------|
|
|
798
|
+
| guardrailProfileArn | string | Yes | The ARN of the system-defined guardrail profile that defines the destination AWS Regions where guardrail inference requests can be automatically routed |
|
|
799
|
+
|
|
800
|
+
##### Cross-Region Configuration Example
|
|
801
|
+
|
|
802
|
+
```ts fixture=default
|
|
803
|
+
const guardrail = new bedrock.Guardrail(this, 'bedrockGuardrails', {
|
|
804
|
+
guardrailName: 'my-BedrockGuardrails',
|
|
805
|
+
description: 'Guardrail with cross-region configuration for enhanced language support',
|
|
806
|
+
crossRegionConfig: {
|
|
807
|
+
guardrailProfileArn: 'arn:aws:bedrock:us-east-1:123456789012:guardrail-profile/my-profile',
|
|
808
|
+
},
|
|
809
|
+
// Use STANDARD tier for enhanced capabilities
|
|
810
|
+
contentFiltersTierConfig: bedrock.TierConfig.STANDARD,
|
|
811
|
+
topicsTierConfig: bedrock.TierConfig.STANDARD,
|
|
812
|
+
});
|
|
813
|
+
```
|
|
814
|
+
|
|
815
|
+
> Note: Cross-region configuration is required when using the STANDARD tier for content and topic filters. It helps maintain guardrail performance and reliability when demand increases by automatically routing inference requests to appropriate regions.
|
|
816
|
+
|
|
817
|
+
You will need to provide the necessary permissions for cross region: https://docs.aws.amazon.com/bedrock/latest/userguide/guardrail-profiles-permissions.html .
|
|
818
|
+
|
|
819
|
+
#### Denied Topics
|
|
820
|
+
|
|
821
|
+
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. You can configure separate actions for input and output.
|
|
822
|
+
|
|
823
|
+
##### Denied Topic Configuration
|
|
824
|
+
|
|
825
|
+
```ts fixture=default
|
|
826
|
+
const guardrail = new bedrock.Guardrail(this, 'bedrockGuardrails', {
|
|
827
|
+
guardrailName: 'my-BedrockGuardrails',
|
|
828
|
+
// Configure tier for topic filters (optional)
|
|
829
|
+
topicsTierConfig: bedrock.TierConfig.STANDARD,
|
|
830
|
+
});
|
|
831
|
+
|
|
832
|
+
// Use a predefined topic
|
|
833
|
+
guardrail.addDeniedTopicFilter(bedrock.Topic.FINANCIAL_ADVICE);
|
|
834
|
+
|
|
835
|
+
// Create a custom topic with input/output actions
|
|
836
|
+
guardrail.addDeniedTopicFilter(
|
|
837
|
+
bedrock.Topic.custom({
|
|
838
|
+
name: 'Legal_Advice',
|
|
839
|
+
definition: 'Offering guidance or suggestions on legal matters, legal actions, interpretation of laws, or legal rights and responsibilities.',
|
|
840
|
+
examples: [
|
|
841
|
+
'Can I sue someone for this?',
|
|
842
|
+
'What are my legal rights in this situation?',
|
|
843
|
+
'Is this action against the law?',
|
|
844
|
+
'What should I do to file a legal complaint?',
|
|
845
|
+
'Can you explain this law to me?',
|
|
846
|
+
],
|
|
847
|
+
// props below are optional
|
|
848
|
+
inputAction: bedrock.GuardrailAction.BLOCK,
|
|
849
|
+
inputEnabled: true,
|
|
850
|
+
outputAction: bedrock.GuardrailAction.NONE,
|
|
851
|
+
outputEnabled: true,
|
|
852
|
+
})
|
|
853
|
+
);
|
|
854
|
+
```
|
|
855
|
+
|
|
856
|
+
#### Word Filters
|
|
857
|
+
|
|
858
|
+
Word filters allow you to block specific words, phrases, or profanity in user inputs and model responses. You can configure separate actions for input and output.
|
|
859
|
+
|
|
860
|
+
##### Word Filter Configuration
|
|
861
|
+
|
|
862
|
+
```ts fixture=default
|
|
863
|
+
const guardrail = new bedrock.Guardrail(this, 'bedrockGuardrails', {
|
|
864
|
+
guardrailName: 'my-BedrockGuardrails',
|
|
865
|
+
});
|
|
866
|
+
|
|
867
|
+
// Add managed word list with input/output actions
|
|
868
|
+
guardrail.addManagedWordListFilter({
|
|
869
|
+
type: bedrock.ManagedWordFilterType.PROFANITY,
|
|
870
|
+
inputAction: bedrock.GuardrailAction.BLOCK,
|
|
871
|
+
inputEnabled: true,
|
|
872
|
+
outputAction: bedrock.GuardrailAction.NONE,
|
|
873
|
+
outputEnabled: true,
|
|
874
|
+
});
|
|
875
|
+
|
|
876
|
+
// Add individual words
|
|
877
|
+
guardrail.addWordFilter({text: 'drugs'});
|
|
878
|
+
guardrail.addWordFilter({text: 'competitor'});
|
|
879
|
+
|
|
880
|
+
// Add words from a file
|
|
881
|
+
guardrail.addWordFilterFromFile('./scripts/wordsPolicy.csv');
|
|
882
|
+
```
|
|
883
|
+
|
|
884
|
+
#### PII Filters
|
|
885
|
+
|
|
886
|
+
PII filters allow you to detect and handle personally identifiable information in user inputs and model responses. You can configure separate actions for input and output.
|
|
887
|
+
|
|
888
|
+
The PII types are organized into enum-like classes for better type safety and transpilation compatibility:
|
|
889
|
+
|
|
890
|
+
- **GeneralPIIType**: General PII types like addresses, emails, names, phone numbers
|
|
891
|
+
- **FinancePIIType**: Financial information like credit card numbers, PINs, SWIFT codes
|
|
892
|
+
- **InformationTechnologyPIIType**: IT-related data like URLs, IP addresses, AWS keys
|
|
893
|
+
- **USASpecificPIIType**: US-specific identifiers like SSNs, passport numbers
|
|
894
|
+
- **CanadaSpecificPIIType**: Canada-specific identifiers like health numbers, SINs
|
|
895
|
+
- **UKSpecificPIIType**: UK-specific identifiers like NHS numbers, NI numbers
|
|
896
|
+
|
|
897
|
+
##### PII Filter Configuration
|
|
898
|
+
|
|
899
|
+
```ts fixture=default
|
|
900
|
+
const guardrail = new bedrock.Guardrail(this, 'bedrockGuardrails', {
|
|
901
|
+
guardrailName: 'my-BedrockGuardrails',
|
|
902
|
+
});
|
|
903
|
+
|
|
904
|
+
// Add PII filter for addresses with input/output actions
|
|
905
|
+
guardrail.addPIIFilter({
|
|
906
|
+
type: bedrock.GeneralPIIType.ADDRESS,
|
|
907
|
+
action: bedrock.GuardrailAction.BLOCK,
|
|
908
|
+
// below props are optional
|
|
909
|
+
inputAction: bedrock.GuardrailAction.BLOCK,
|
|
910
|
+
inputEnabled: true,
|
|
911
|
+
outputAction: bedrock.GuardrailAction.ANONYMIZE,
|
|
912
|
+
outputEnabled: true,
|
|
913
|
+
});
|
|
914
|
+
|
|
915
|
+
// Add PII filter for credit card numbers with input/output actions
|
|
916
|
+
guardrail.addPIIFilter({
|
|
917
|
+
type: bedrock.FinancePIIType.CREDIT_DEBIT_CARD_NUMBER,
|
|
918
|
+
action: bedrock.GuardrailAction.BLOCK,
|
|
919
|
+
// below props are optional
|
|
920
|
+
inputAction: bedrock.GuardrailAction.BLOCK,
|
|
921
|
+
inputEnabled: true,
|
|
922
|
+
outputAction: bedrock.GuardrailAction.ANONYMIZE,
|
|
923
|
+
outputEnabled: true,
|
|
924
|
+
});
|
|
925
|
+
|
|
926
|
+
// Add PII filter for email addresses
|
|
927
|
+
guardrail.addPIIFilter({
|
|
928
|
+
type: bedrock.GeneralPIIType.EMAIL,
|
|
929
|
+
action: bedrock.GuardrailAction.ANONYMIZE,
|
|
930
|
+
});
|
|
931
|
+
|
|
932
|
+
// Add PII filter for US Social Security Numbers
|
|
933
|
+
guardrail.addPIIFilter({
|
|
934
|
+
type: bedrock.USASpecificPIIType.US_SOCIAL_SECURITY_NUMBER,
|
|
935
|
+
action: bedrock.GuardrailAction.BLOCK,
|
|
936
|
+
});
|
|
937
|
+
|
|
938
|
+
// Add PII filter for IP addresses
|
|
939
|
+
guardrail.addPIIFilter({
|
|
940
|
+
type: bedrock.InformationTechnologyPIIType.IP_ADDRESS,
|
|
941
|
+
action: bedrock.GuardrailAction.ANONYMIZE,
|
|
942
|
+
});
|
|
943
|
+
```
|
|
944
|
+
|
|
945
|
+
##### Available PII Types
|
|
946
|
+
|
|
947
|
+
**GeneralPIIType:**
|
|
948
|
+
|
|
949
|
+
- `ADDRESS`: Physical addresses
|
|
950
|
+
- `AGE`: Individual's age
|
|
951
|
+
- `DRIVER_ID`: Driver's license numbers
|
|
952
|
+
- `EMAIL`: Email addresses
|
|
953
|
+
- `LICENSE_PLATE`: Vehicle license plates
|
|
954
|
+
- `NAME`: Individual names
|
|
955
|
+
- `PASSWORD`: Passwords
|
|
956
|
+
- `PHONE`: Phone numbers
|
|
957
|
+
- `USERNAME`: User account names
|
|
958
|
+
- `VEHICLE_IDENTIFICATION_NUMBER`: Vehicle VINs
|
|
959
|
+
|
|
960
|
+
**FinancePIIType:**
|
|
961
|
+
|
|
962
|
+
- `CREDIT_DEBIT_CARD_CVV`: Card verification codes
|
|
963
|
+
- `CREDIT_DEBIT_CARD_EXPIRY`: Card expiration dates
|
|
964
|
+
- `CREDIT_DEBIT_CARD_NUMBER`: Credit/debit card numbers
|
|
965
|
+
- `PIN`: Personal identification numbers
|
|
966
|
+
- `SWIFT_CODE`: Bank SWIFT codes
|
|
967
|
+
- `INTERNATIONAL_BANK_ACCOUNT_NUMBER`: IBAN numbers
|
|
968
|
+
|
|
969
|
+
**InformationTechnologyPIIType:**
|
|
970
|
+
|
|
971
|
+
- `URL`: Web addresses
|
|
972
|
+
- `IP_ADDRESS`: IPv4 addresses
|
|
973
|
+
- `MAC_ADDRESS`: Network interface MAC addresses
|
|
974
|
+
- `AWS_ACCESS_KEY`: AWS access key IDs
|
|
975
|
+
- `AWS_SECRET_KEY`: AWS secret access keys
|
|
976
|
+
|
|
977
|
+
**USASpecificPIIType:**
|
|
978
|
+
|
|
979
|
+
- `US_BANK_ACCOUNT_NUMBER`: US bank account numbers
|
|
980
|
+
- `US_BANK_ROUTING_NUMBER`: US bank routing numbers
|
|
981
|
+
- `US_INDIVIDUAL_TAX_IDENTIFICATION_NUMBER`: US ITINs
|
|
982
|
+
- `US_PASSPORT_NUMBER`: US passport numbers
|
|
983
|
+
- `US_SOCIAL_SECURITY_NUMBER`: US Social Security Numbers
|
|
984
|
+
|
|
985
|
+
**CanadaSpecificPIIType:**
|
|
986
|
+
|
|
987
|
+
- `CA_HEALTH_NUMBER`: Canadian Health Service Numbers
|
|
988
|
+
- `CA_SOCIAL_INSURANCE_NUMBER`: Canadian Social Insurance Numbers
|
|
989
|
+
|
|
990
|
+
**UKSpecificPIIType:**
|
|
991
|
+
|
|
992
|
+
- `UK_NATIONAL_HEALTH_SERVICE_NUMBER`: UK NHS numbers
|
|
993
|
+
- `UK_NATIONAL_INSURANCE_NUMBER`: UK National Insurance numbers
|
|
994
|
+
- `UK_UNIQUE_TAXPAYER_REFERENCE_NUMBER`: UK UTR numbers
|
|
995
|
+
|
|
996
|
+
#### Regex Filters
|
|
997
|
+
|
|
998
|
+
Regex filters allow you to detect and handle custom patterns in user inputs and model responses. You can configure separate actions for input and output.
|
|
999
|
+
|
|
1000
|
+
##### Regex Filter Configuration
|
|
1001
|
+
|
|
1002
|
+
```ts fixture=default
|
|
1003
|
+
const guardrail = new bedrock.Guardrail(this, 'bedrockGuardrails', {
|
|
1004
|
+
guardrailName: 'my-BedrockGuardrails',
|
|
1005
|
+
});
|
|
1006
|
+
// Add regex filter with input/output actions
|
|
1007
|
+
guardrail.addRegexFilter({
|
|
1008
|
+
name: 'TestRegexFilter',
|
|
1009
|
+
pattern: 'test-pattern',
|
|
1010
|
+
action: bedrock.GuardrailAction.ANONYMIZE,
|
|
1011
|
+
// below props are optional
|
|
1012
|
+
description: 'This is a test regex filter',
|
|
1013
|
+
inputAction: bedrock.GuardrailAction.BLOCK,
|
|
1014
|
+
inputEnabled: true,
|
|
1015
|
+
outputAction: bedrock.GuardrailAction.ANONYMIZE,
|
|
1016
|
+
outputEnabled: true,
|
|
1017
|
+
});
|
|
1018
|
+
```
|
|
1019
|
+
|
|
1020
|
+
#### Contextual Grounding Filters
|
|
1021
|
+
|
|
1022
|
+
Contextual grounding filters allow you to ensure that model responses are factually correct and relevant to the user's query. You can configure the action and enable/disable the filter.
|
|
1023
|
+
|
|
1024
|
+
##### Contextual Grounding Filter Configuration
|
|
1025
|
+
|
|
1026
|
+
```ts fixture=default
|
|
1027
|
+
const guardrail = new bedrock.Guardrail(this, 'bedrockGuardrails', {
|
|
1028
|
+
guardrailName: 'my-BedrockGuardrails',
|
|
1029
|
+
});
|
|
1030
|
+
// Add contextual grounding filter with action and enabled flag
|
|
1031
|
+
guardrail.addContextualGroundingFilter({
|
|
1032
|
+
type: bedrock.ContextualGroundingFilterType.GROUNDING,
|
|
1033
|
+
threshold: 0.8,
|
|
1034
|
+
// the properties below are optional
|
|
1035
|
+
action: bedrock.GuardrailAction.BLOCK,
|
|
1036
|
+
enabled: true,
|
|
1037
|
+
});
|
|
1038
|
+
```
|
|
1039
|
+
|
|
1040
|
+
### Guardrail Methods
|
|
1041
|
+
|
|
1042
|
+
| Method | Description |
|
|
1043
|
+
|--------|-------------|
|
|
1044
|
+
| `addContentFilter()` | Adds a content filter to the guardrail |
|
|
1045
|
+
| `addDeniedTopicFilter()` | Adds a denied topic filter to the guardrail |
|
|
1046
|
+
| `addWordFilter()` | Adds a word filter to the guardrail |
|
|
1047
|
+
| `addManagedWordListFilter()` | Adds a managed word list filter to the guardrail |
|
|
1048
|
+
| `addWordFilterFromFile()` | Adds word filters from a file to the guardrail |
|
|
1049
|
+
| `addPIIFilter()` | Adds a PII filter to the guardrail |
|
|
1050
|
+
| `addRegexFilter()` | Adds a regex filter to the guardrail |
|
|
1051
|
+
| `addContextualGroundingFilter()` | Adds a contextual grounding filter to the guardrail |
|
|
1052
|
+
| `createVersion()` | Creates a new version of the guardrail |
|
|
1053
|
+
|
|
1054
|
+
### Guardrail Permissions
|
|
1055
|
+
|
|
1056
|
+
Guardrails provide methods to grant permissions to other resources that need to interact with the guardrail.
|
|
1057
|
+
|
|
1058
|
+
#### Permission Methods
|
|
1059
|
+
|
|
1060
|
+
| Method | Description | Parameters |
|
|
1061
|
+
|--------|-------------|------------|
|
|
1062
|
+
| `grant(grantee, ...actions)` | Grants the given principal identity permissions to perform actions on this guardrail | `grantee`: The principal to grant permissions to<br>`actions`: The actions to grant (e.g., `bedrock:GetGuardrail`, `bedrock:ListGuardrails`) |
|
|
1063
|
+
| `grantApply(grantee)` | Grants the given identity permissions to apply the guardrail | `grantee`: The principal to grant permissions to |
|
|
1064
|
+
|
|
1065
|
+
#### Permission Examples
|
|
1066
|
+
|
|
1067
|
+
```ts fixture=default
|
|
1068
|
+
const guardrail = new bedrock.Guardrail(this, 'bedrockGuardrails', {
|
|
1069
|
+
guardrailName: 'my-BedrockGuardrails',
|
|
1070
|
+
});
|
|
1071
|
+
|
|
1072
|
+
const lambdaFunction = new lambda.Function(this, 'testLambda', {
|
|
1073
|
+
runtime: lambda.Runtime.PYTHON_3_12,
|
|
1074
|
+
handler: 'index.handler',
|
|
1075
|
+
code: lambda.Code.fromAsset(path.join(__dirname, '../lambda/my-code')),
|
|
1076
|
+
});
|
|
1077
|
+
|
|
1078
|
+
// Grant specific permissions to a Lambda function
|
|
1079
|
+
guardrail.grant(lambdaFunction, 'bedrock:GetGuardrail', 'bedrock:ListGuardrails');
|
|
1080
|
+
|
|
1081
|
+
// Grant permissions to apply the guardrail
|
|
1082
|
+
guardrail.grantApply(lambdaFunction);
|
|
1083
|
+
```
|
|
1084
|
+
|
|
1085
|
+
### Guardrail Metrics
|
|
1086
|
+
|
|
1087
|
+
Amazon Bedrock provides metrics for your guardrails, allowing you to monitor their effectiveness and usage. These metrics are available in CloudWatch and can be used to create dashboards and alarms.
|
|
1088
|
+
|
|
1089
|
+
#### Metrics Examples
|
|
1090
|
+
|
|
1091
|
+
```ts fixture=default
|
|
1092
|
+
import * as cloudwatch from 'aws-cdk-lib/aws-cloudwatch';
|
|
1093
|
+
|
|
1094
|
+
const guardrail = new bedrock.Guardrail(this, 'bedrockGuardrails', {
|
|
1095
|
+
guardrailName: 'my-BedrockGuardrails',
|
|
1096
|
+
});
|
|
1097
|
+
// Get a specific metric for this guardrail
|
|
1098
|
+
const invocationsMetric = guardrail.metricInvocations({
|
|
1099
|
+
statistic: 'Sum',
|
|
1100
|
+
period: Duration.minutes(5),
|
|
1101
|
+
});
|
|
1102
|
+
|
|
1103
|
+
// Create a CloudWatch alarm for high invocation latency
|
|
1104
|
+
new cloudwatch.Alarm(this, 'HighLatencyAlarm', {
|
|
1105
|
+
metric: guardrail.metricInvocationLatency(),
|
|
1106
|
+
threshold: 1000, // 1 second
|
|
1107
|
+
evaluationPeriods: 3,
|
|
1108
|
+
});
|
|
1109
|
+
|
|
1110
|
+
// Get metrics for all guardrails
|
|
1111
|
+
const allInvocationsMetric = bedrock.Guardrail.metricAllInvocations();
|
|
1112
|
+
```
|
|
1113
|
+
|
|
1114
|
+
### Importing Guardrails
|
|
1115
|
+
|
|
1116
|
+
You can import existing guardrails using the `fromGuardrailAttributes` or `fromCfnGuardrail` methods.
|
|
1117
|
+
|
|
1118
|
+
#### Import Configuration
|
|
1119
|
+
|
|
1120
|
+
```ts fixture=default
|
|
1121
|
+
declare const stack: Stack;
|
|
1122
|
+
const cmk = new kms.Key(this, 'cmk', {});
|
|
1123
|
+
// Import an existing guardrail by ARN
|
|
1124
|
+
const importedGuardrail = bedrock.Guardrail.fromGuardrailAttributes(stack, 'TestGuardrail', {
|
|
1125
|
+
guardrailArn: 'arn:aws:bedrock:us-east-1:123456789012:guardrail/oygh3o8g7rtl',
|
|
1126
|
+
guardrailVersion: '1', //optional
|
|
1127
|
+
kmsKey: cmk, //optional
|
|
1128
|
+
});
|
|
1129
|
+
```
|
|
1130
|
+
|
|
1131
|
+
```ts fixture=default
|
|
1132
|
+
import * as bedrockl1 from 'aws-cdk-lib/aws-bedrock';
|
|
1133
|
+
// Import a guardrail created through the L1 CDK CfnGuardrail construct
|
|
1134
|
+
const l1guardrail = new bedrockl1.CfnGuardrail(this, 'MyCfnGuardrail', {
|
|
1135
|
+
blockedInputMessaging: 'blockedInputMessaging',
|
|
1136
|
+
blockedOutputsMessaging: 'blockedOutputsMessaging',
|
|
1137
|
+
name: 'namemycfnguardrails',
|
|
1138
|
+
wordPolicyConfig: {
|
|
1139
|
+
wordsConfig: [
|
|
1140
|
+
{
|
|
1141
|
+
text: 'drugs',
|
|
1142
|
+
},
|
|
1143
|
+
],
|
|
1144
|
+
},
|
|
1145
|
+
});
|
|
1146
|
+
|
|
1147
|
+
const importedGuardrail = bedrock.Guardrail.fromCfnGuardrail(l1guardrail);
|
|
1148
|
+
```
|
|
1149
|
+
|
|
1150
|
+
### Guardrail Versioning
|
|
1151
|
+
|
|
1152
|
+
Guardrails support versioning, allowing you to track changes and maintain multiple versions of your guardrail configurations.
|
|
1153
|
+
|
|
1154
|
+
#### Version Configuration
|
|
1155
|
+
|
|
1156
|
+
```ts fixture=default
|
|
1157
|
+
const guardrail = new bedrock.Guardrail(this, 'bedrockGuardrails', {
|
|
1158
|
+
guardrailName: 'my-BedrockGuardrails',
|
|
1159
|
+
});
|
|
1160
|
+
// Create a new version of the guardrail
|
|
1161
|
+
guardrail.createVersion('testversion');
|
|
1162
|
+
```
|
|
1163
|
+
|
|
624
1164
|
## Prompts
|
|
625
1165
|
|
|
626
1166
|
Amazon Bedrock provides the ability to create and save prompts using Prompt management so that you can save time by applying the same prompt to different workflows. You can include variables in the prompt so that you can adjust the prompt for different use case.
|