Skip to content

Conversation

@krokoko
Copy link
Collaborator

@krokoko krokoko commented Apr 23, 2025

Fixes #1092

  • Upgrades base cdk version to v2.191.0
  • Add new properties added to guardrails in aws/aws-cdk@adfa416 . /!\ This has some breaking changes due to additional props for Word and ManagedWord filters.
  • Add new prop TextIndexName for MongoDBAtlas
  • Add support for OpenSearch Managed cluster in KB as a vector store

Testing:

  • tested guardrails with the following code snippet:
const guardrail = new bedrock.Guardrail(this, 'bedrockGuardrails', {
      name: 'my-BedrockGuardrails',
      description: 'Legal ethical guardrails.',
    });

    guardrail.addContentFilter({
      type: bedrock.ContentFilterType.SEXUAL,
      inputStrength: bedrock.ContentFilterStrength.HIGH,
      outputStrength: bedrock.ContentFilterStrength.MEDIUM,
      inputAction: bedrock.GuardrailAction.BLOCK,
      inputEnabled: true,
      outputAction: bedrock.GuardrailAction.NONE,
      outputEnabled: true,
      inputModalities: [bedrock.ModalityType.TEXT, bedrock.ModalityType.IMAGE],
      outputModalities: [bedrock.ModalityType.TEXT],
    });

    guardrail.addDeniedTopicFilter(bedrock.Topic.FINANCIAL_ADVICE);

    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?',
        ],
        inputAction: bedrock.GuardrailAction.BLOCK,
        inputEnabled: true,
        outputAction: bedrock.GuardrailAction.NONE,
        outputEnabled: true,
      })
    );

    guardrail.addManagedWordListFilter({
      type: bedrock.ManagedWordFilterType.PROFANITY,
      inputAction: bedrock.GuardrailAction.BLOCK,
      inputEnabled: true,
      outputAction: bedrock.GuardrailAction.NONE,
      outputEnabled: true,
    });
    
    // Add individual words
    guardrail.addWordFilter({text: 'drugs'});
    guardrail.addWordFilter({text: 'competitor'});

    guardrail.addWordFilter({
      text: 'violence',
      inputAction: bedrock.GuardrailAction.BLOCK, 
      inputEnabled: true, 
      outputAction: bedrock.GuardrailAction.NONE, 
      outputEnabled: true
    });

    guardrail.addPIIFilter({
      type: bedrock.PIIType.General.ADDRESS,
      action: bedrock.GuardrailAction.BLOCK,
      inputAction: bedrock.GuardrailAction.BLOCK,
      inputEnabled: true,
      outputAction: bedrock.GuardrailAction.ANONYMIZE,
      outputEnabled: true,
    });
    
    // Add PII filter for credit card numbers with input/output actions
    guardrail.addPIIFilter({
      type: bedrock.PIIType.General.LICENSE_PLATE,
      action: bedrock.GuardrailAction.BLOCK,
      inputAction: bedrock.GuardrailAction.BLOCK,
      inputEnabled: true,
      outputAction: bedrock.GuardrailAction.ANONYMIZE,
      outputEnabled: true,
    });

    guardrail.addRegexFilter({
      name: 'TestRegexFilter',
      description: 'This is a test regex filter',
      pattern: '/^[A-Z]{2}d{6}$/',
      action: bedrock.GuardrailAction.ANONYMIZE,
      inputAction: bedrock.GuardrailAction.BLOCK,
      inputEnabled: true,
      outputAction: bedrock.GuardrailAction.ANONYMIZE,
      outputEnabled: true,
    });

    guardrail.addContextualGroundingFilter({
      type: bedrock.ContextualGroundingFilterType.GROUNDING,
      action: bedrock.GuardrailAction.BLOCK,
      enabled: true,
      threshold: 0.8,
    });

Deploys and works as expected


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.

@krokoko krokoko marked this pull request as ready for review April 23, 2025 22:58
@krokoko krokoko requested a review from a team as a code owner April 23, 2025 22:58
Copy link
Contributor

@MichaelWalker-git MichaelWalker-git left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@dineshSajwan dineshSajwan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks all good.

@mergify
Copy link
Contributor

mergify bot commented Apr 28, 2025

This pull request has been removed from the queue for the following reason: pull request dequeued.

Pull request #1097 has been dequeued. The pull request could not be merged. This could be related to an activated branch protection or ruleset rule that prevents us from merging. (details: You're not authorized to push to this branch. Visit https://docs.github.com/repositories/configuring-branches-and-merges-in-your-repository/managing-protected-branches/about-protected-branches for more information.).

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio requeue comment.

@krokoko krokoko merged commit 2178fee into awslabs:main Apr 28, 2025
12 of 15 checks passed
@krokoko krokoko deleted the upgrade2191 branch October 15, 2025 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bedrock KB: add support for OpenSearch managed cluster

5 participants