|
| 1 | +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +using System.Collections.Generic; |
| 5 | +using System.Threading.Tasks; |
| 6 | +using AWS.Bedrock.MAG; |
| 7 | +using AWS.Bedrock.MAG.IntegrationTests.Infrastructure; |
| 8 | +using AWS.Bedrock.MAG.Policy; |
| 9 | +using Xunit; |
| 10 | + |
| 11 | +namespace AWS.Bedrock.MAG.IntegrationTests |
| 12 | +{ |
| 13 | + /// <summary> |
| 14 | + /// Runs the policy backend in inline-checks mode against real InvokeGuardrailChecks, i.e. with no |
| 15 | + /// pre-created guardrail (PR: InvokeGuardrailChecks). |
| 16 | + /// </summary> |
| 17 | + [Collection("bedrock-integration")] |
| 18 | + public class InlineChecksIntegrationTests |
| 19 | + { |
| 20 | + private readonly GuardrailFixture _fx; |
| 21 | + |
| 22 | + public InlineChecksIntegrationTests(GuardrailFixture fx) => _fx = fx; |
| 23 | + |
| 24 | + private BedrockGuardrailsPolicyBackend Backend() |
| 25 | + { |
| 26 | + var options = new BedrockGuardrailsPolicyOptions |
| 27 | + { |
| 28 | + Region = _fx.Region, |
| 29 | + InlineChecks = new GuardrailChecksOptions { ConfidenceThreshold = 0.1 } |
| 30 | + }; |
| 31 | + options.InlineChecks.SensitiveInformationEntities.Add("US_SOCIAL_SECURITY_NUMBER"); |
| 32 | + return new BedrockGuardrailsPolicyBackend(options); |
| 33 | + } |
| 34 | + |
| 35 | + [Fact] |
| 36 | + public async Task Denies_when_inline_pii_check_detects_an_ssn() |
| 37 | + { |
| 38 | + if (_fx.SkipReason is { } reason) |
| 39 | + { |
| 40 | + Assert.Skip(reason); |
| 41 | + } |
| 42 | + |
| 43 | + var decision = await Backend().EvaluateAsync(new Dictionary<string, object> |
| 44 | + { |
| 45 | + ["tool"] = "lookup", |
| 46 | + ["arg"] = "the ssn is 123-45-6789" |
| 47 | + }); |
| 48 | + |
| 49 | + Assert.False(decision.Allowed); |
| 50 | + } |
| 51 | + |
| 52 | + [Fact] |
| 53 | + public async Task Allows_when_inline_pii_check_finds_nothing() |
| 54 | + { |
| 55 | + if (_fx.SkipReason is { } reason) |
| 56 | + { |
| 57 | + Assert.Skip(reason); |
| 58 | + } |
| 59 | + |
| 60 | + var decision = await Backend().EvaluateAsync(new Dictionary<string, object> |
| 61 | + { |
| 62 | + ["tool"] = "lookup", |
| 63 | + ["arg"] = "the weather is sunny today" |
| 64 | + }); |
| 65 | + |
| 66 | + Assert.True(decision.Allowed, decision.Reason); |
| 67 | + } |
| 68 | + } |
| 69 | +} |
0 commit comments