Skip to content
v2.278.0

Experimental

@aws-cdk/aws-bedrock-alpha is an experimental (alpha) package: its API may change in any release, without a major version bump.

ContentFilter Struct ​

Interface to declare a content filter.

Example ​

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
# 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
// 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();
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
});
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 ​

inputActionoptionalGuardrailActioninput_actionoptionalGuardrailActioninputActionoptionalGuardrailActionInputActionoptionalGuardrailActionInputActionoptionalGuardrailAction = GuardrailAction.BLOCK #
The action to take when content is detected in the input.
inputEnabledoptionalbooleaninput_enabledoptionalboolinputEnabledoptionalBooleanInputEnabledoptionalboolInputEnabledoptional*bool = true #
Whether the content filter is enabled for input.
inputModalitiesoptionalModalityType[]input_modalitiesoptionaltyping.List[ModalityType]inputModalitiesoptionalList<ModalityType>InputModalitiesoptionalModalityType[]InputModalitiesoptional*[]ModalityType #
The input modalities to apply the content filter to.

Default: undefined - Applies to text modality

inputStrengthContentFilterStrengthinput_strengthContentFilterStrengthinputStrengthContentFilterStrengthInputStrengthContentFilterStrengthInputStrengthContentFilterStrength required #
The strength of the content filter to apply to prompts / user input.
outputActionoptionalGuardrailActionoutput_actionoptionalGuardrailActionoutputActionoptionalGuardrailActionOutputActionoptionalGuardrailActionOutputActionoptionalGuardrailAction = GuardrailAction.BLOCK #
The action to take when content is detected in the output.
outputEnabledoptionalbooleanoutput_enabledoptionalbooloutputEnabledoptionalBooleanOutputEnabledoptionalboolOutputEnabledoptional*bool = true #
Whether the content filter is enabled for output.
outputModalitiesoptionalModalityType[]output_modalitiesoptionaltyping.List[ModalityType]outputModalitiesoptionalList<ModalityType>OutputModalitiesoptionalModalityType[]OutputModalitiesoptional*[]ModalityType #
The output modalities to apply the content filter to.

Default: undefined - Applies to text modality

outputStrengthContentFilterStrengthoutput_strengthContentFilterStrengthoutputStrengthContentFilterStrengthOutputStrengthContentFilterStrengthOutputStrengthContentFilterStrength required #
The strength of the content filter to apply to model responses.
The type of harmful category that the content filter is applied to.