Experimental
@aws-cdk/aws-bedrock-alpha is an experimental (alpha) package: its API may change in any release, without a major version bump.
ContextualGroundingFilter Struct
Interface to define a Contextual Grounding Filter.
| Stability | Experimental |
|---|---|
| Source | bedrock/guardrails/guardrail-filters.ts |
Example
ts
const guardrail = new bedrock.Guardrail(this, 'bedrockGuardrails', {
guardrailName: 'my-BedrockGuardrails',
});
// Add contextual grounding filter with action and enabled flag
guardrail.addContextualGroundingFilter({
type: bedrock.ContextualGroundingFilterType.GROUNDING,
threshold: 0.8,
// the properties below are optional
action: bedrock.GuardrailAction.BLOCK,
enabled: true,
});
python
guardrail = bedrock.Guardrail(self, "bedrockGuardrails",
guardrail_name="my-BedrockGuardrails"
)
# Add contextual grounding filter with action and enabled flag
guardrail.add_contextual_grounding_filter(
type=bedrock.ContextualGroundingFilterType.GROUNDING,
threshold=0.8,
# the properties below are optional
action=bedrock.GuardrailAction.BLOCK,
enabled=True
)
java
Guardrail guardrail = Guardrail.Builder.create(this, "bedrockGuardrails")
.guardrailName("my-BedrockGuardrails")
.build();
// Add contextual grounding filter with action and enabled flag
guardrail.addContextualGroundingFilter(ContextualGroundingFilter.builder()
.type(ContextualGroundingFilterType.GROUNDING)
.threshold(0.8)
// the properties below are optional
.action(GuardrailAction.BLOCK)
.enabled(true)
.build());
csharp
// Install: dotnet add package Amazon.CDK.AWS.Bedrock.Alpha
var guardrail = new Guardrail(this, "bedrockGuardrails", new GuardrailProps {
GuardrailName = "my-BedrockGuardrails"
});
// Add contextual grounding filter with action and enabled flag
guardrail.AddContextualGroundingFilter(new ContextualGroundingFilter {
Type = ContextualGroundingFilterType.GROUNDING,
Threshold = 0.8,
// the properties below are optional
Action = GuardrailAction.BLOCK,
Enabled = true
});
go
// Install: go get github.com/aws/aws-cdk-go/awsbedrockalpha/v2
guardrail := bedrock.NewGuardrail(this, jsii.String("bedrockGuardrails"), &GuardrailProps{
GuardrailName: jsii.String("my-BedrockGuardrails"),
})
// Add contextual grounding filter with action and enabled flag
guardrail.AddContextualGroundingFilter(&ContextualGroundingFilter{
Type: bedrock.ContextualGroundingFilterType_GROUNDING,
Threshold: jsii.Number(0.8),
// the properties below are optional
Action: bedrock.GuardrailAction_BLOCK,
Enabled: jsii.Boolean(true),
})
Properties
actionoptionalGuardrailActionactionoptionalGuardrailActionactionoptionalGuardrailActionActionoptionalGuardrailActionActionoptionalGuardrailAction = GuardrailAction.BLOCK #The action to take when contextual grounding is detected.
enabledoptionalbooleanenabledoptionalboolenabledoptionalBooleanEnabledoptionalboolEnabledoptional*bool = true #Whether the contextual grounding filter is enabled.
The threshold for the contextual grounding filter.
0(blocks nothing)0.99(blocks almost everything)
typeContextualGroundingFilterTypetypeContextualGroundingFilterTypetypeContextualGroundingFilterTypeTypeContextualGroundingFilterTypeTypeContextualGroundingFilterType required #The type of contextual grounding filter.