awslabs / generative-ai-cdk-constructs

AWS Generative AI CDK Constructs are sample implementations of AWS CDK for common generative AI patterns.
https://awslabs.github.io/generative-ai-cdk-constructs/
Apache License 2.0
337 stars 51 forks source link

feat(guardrails): add Contextual grounding #660

Closed krokoko closed 1 month ago

krokoko commented 1 month ago

Fixes #656

Pending testing

guardrails.addContextualGroundingPolicyConfig([
      {
        threshold: 0.5,
        filtersConfigType: bedrock.ContextualGroundingFilterConfigType.GROUNDING,
      },
      {
        threshold: 0.9,
        filtersConfigType: bedrock.ContextualGroundingFilterConfigType.RELEVANCE,
      },
    ]);

image

Agent has guardrails attached:

image

When asking a question with a response factually correct:

image

Examples when blocking:

image


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