> **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.
# ContentFilter

Interface to declare a content filter.

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

- 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#L122)

## Example

TypeScript:

```ts
// Create a guardrail to filter inappropriate content
const guardrail = new bedrock.Guardrail(this, 'bedrockGuardrails', {
  guardrailName: 'my-BedrockGuardrails',
  description: 'Legal ethical guardrails.',
});

guardrail.addContentFilter({
  type: bedrock.ContentFilterType.SEXUAL,
  inputStrength: bedrock.ContentFilterStrength.HIGH,
  outputStrength: bedrock.ContentFilterStrength.MEDIUM,
});

// Create an agent with the guardrail
const agentWithGuardrail = new bedrock.Agent(this, 'AgentWithGuardrail', {
  foundationModel: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
  instruction: 'You are a helpful and friendly agent that answers questions about literature.',
  guardrail: guardrail,
});
```

Python:

```python
# Create a guardrail to filter inappropriate content
guardrail = bedrock.Guardrail(self, "bedrockGuardrails",
    guardrail_name="my-BedrockGuardrails",
    description="Legal ethical guardrails."
)

guardrail.add_content_filter(
    type=bedrock.ContentFilterType.SEXUAL,
    input_strength=bedrock.ContentFilterStrength.HIGH,
    output_strength=bedrock.ContentFilterStrength.MEDIUM
)

# Create an agent with the guardrail
agent_with_guardrail = bedrock.Agent(self, "AgentWithGuardrail",
    foundation_model=bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
    instruction="You are a helpful and friendly agent that answers questions about literature.",
    guardrail=guardrail
)
```

Java:

```java
// Create a guardrail to filter inappropriate content
Guardrail guardrail = Guardrail.Builder.create(this, "bedrockGuardrails")
        .guardrailName("my-BedrockGuardrails")
        .description("Legal ethical guardrails.")
        .build();

guardrail.addContentFilter(ContentFilter.builder()
        .type(ContentFilterType.SEXUAL)
        .inputStrength(ContentFilterStrength.HIGH)
        .outputStrength(ContentFilterStrength.MEDIUM)
        .build());

// Create an agent with the guardrail
Agent agentWithGuardrail = Agent.Builder.create(this, "AgentWithGuardrail")
        .foundationModel(BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0)
        .instruction("You are a helpful and friendly agent that answers questions about literature.")
        .guardrail(guardrail)
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.AWS.Bedrock.Alpha
// Create a guardrail to filter inappropriate content
var guardrail = new Guardrail(this, "bedrockGuardrails", new GuardrailProps {
    GuardrailName = "my-BedrockGuardrails",
    Description = "Legal ethical guardrails."
});

guardrail.AddContentFilter(new ContentFilter {
    Type = ContentFilterType.SEXUAL,
    InputStrength = ContentFilterStrength.HIGH,
    OutputStrength = ContentFilterStrength.MEDIUM
});

// Create an agent with the guardrail
var agentWithGuardrail = new Agent(this, "AgentWithGuardrail", new AgentProps {
    FoundationModel = BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
    Instruction = "You are a helpful and friendly agent that answers questions about literature.",
    Guardrail = guardrail
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awsbedrockalpha/v2
// Create a guardrail to filter inappropriate content
guardrail := bedrock.NewGuardrail(this, jsii.String("bedrockGuardrails"), &GuardrailProps{
	GuardrailName: jsii.String("my-BedrockGuardrails"),
	Description: jsii.String("Legal ethical guardrails."),
})

guardrail.AddContentFilter(&ContentFilter{
	Type: bedrock.ContentFilterType_SEXUAL,
	InputStrength: bedrock.ContentFilterStrength_HIGH,
	OutputStrength: bedrock.ContentFilterStrength_MEDIUM,
})

// Create an agent with the guardrail
agentWithGuardrail := bedrock.NewAgent(this, jsii.String("AgentWithGuardrail"), &AgentProps{
	FoundationModel: bedrock.BedrockFoundationModel_ANTHROPIC_CLAUDE_HAIKU_V1_0(),
	Instruction: jsii.String("You are a helpful and friendly agent that answers questions about literature."),
	Guardrail: guardrail,
})
```

## Properties

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

- `inputEnabled`: boolean = true — Whether the content filter is enabled for input.

- `inputModalities`: [ModalityType](https://docs.aws.amazon.com/cdk/api/v2/docs/@aws-cdk_aws-bedrock-alpha.ModalityType.html)[] — The input modalities to apply the content filter to.

  **Default:** undefined - Applies to text modality

- `inputStrength`: [ContentFilterStrength](https://docs.aws.amazon.com/cdk/api/v2/docs/@aws-cdk_aws-bedrock-alpha.ContentFilterStrength.html) (required) — The strength of the content filter to apply to prompts / user input.

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

- `outputEnabled`: boolean = true — Whether the content filter is enabled for output.

- `outputModalities`: [ModalityType](https://docs.aws.amazon.com/cdk/api/v2/docs/@aws-cdk_aws-bedrock-alpha.ModalityType.html)[] — The output modalities to apply the content filter to.

  **Default:** undefined - Applies to text modality

- `outputStrength`: [ContentFilterStrength](https://docs.aws.amazon.com/cdk/api/v2/docs/@aws-cdk_aws-bedrock-alpha.ContentFilterStrength.html) (required) — The strength of the content filter to apply to model responses.

- `type`: [ContentFilterType](https://docs.aws.amazon.com/cdk/api/v2/docs/@aws-cdk_aws-bedrock-alpha.ContentFilterType.html) (required) — The type of harmful category that the content filter is applied to.
