> **Experimental**
>
> `@aws-cdk/aws-bedrock-alpha` is an [**experimental**](https://docs.aws.amazon.com/cdk/api/stability.html) (alpha) package: its API may change in any release, without a major version bump.
# ContextualGroundingFilter

Interface to define a Contextual Grounding Filter.

Used as argument in: [Guardrail.addContextualGroundingFilter](https://docs.aws.amazon.com/cdk/api/v2/docs/@aws-cdk_aws-bedrock-alpha.Guardrail.html#addcontextualgroundingfilter)

- Stability: [Experimental](https://docs.aws.amazon.com/cdk/api/stability.html)
- Source: [`bedrock/guardrails/guardrail-filters.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/@aws-cdk/aws-bedrock-alpha/bedrock/guardrails/guardrail-filters.ts#L800)

## Example

TypeScript:

```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:

```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:

```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());
```

C# / .NET:

```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
});
```

Golang:

```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

- `action`: [GuardrailAction](https://docs.aws.amazon.com/cdk/api/v2/docs/@aws-cdk_aws-bedrock-alpha.GuardrailAction.html) = GuardrailAction.BLOCK — The action to take when contextual grounding is detected.

- `enabled`: boolean = true — Whether the contextual grounding filter is enabled.

- `threshold`: number (required) — The threshold for the contextual grounding filter.

  - `0` (blocks nothing)
  - `0.99` (blocks almost everything)

- `type`: [ContextualGroundingFilterType](https://docs.aws.amazon.com/cdk/api/v2/docs/@aws-cdk_aws-bedrock-alpha.ContextualGroundingFilterType.html) (required) — The type of contextual grounding filter.
