MDAA TS Docs
    Preparing search index...

    Module @aws-mdaa/bedrock-guardrail-l3-construct

    Bedrock Guardrail L3 Construct

    This construct provides a high-level abstraction for creating Amazon Bedrock Guardrails for content filtering and safety.

    • Content Filtering: Support for multiple content filter types (hate, sexual, violence, etc.)
    • Contextual Grounding: Grounding and relevance threshold controls
    • Custom Messages: Configurable blocked input/output messages
    • KMS Encryption: Automatic encryption with customer-managed keys
    • Intervention Alarms: (Optional) CloudWatch alarms on the guardrail's intervention count and/or rate, across every guardrail version
    • Flexible Configuration: Support for all guardrail filter strengths
    import { BedrockGuardrailL3Construct } from '@aws-mdaa/bedrock-guardrail-l3-construct';

    const guardrail = new BedrockGuardrailL3Construct(this, 'MyGuardrail', {
    guardrailName: 'my-guardrail',
    guardrailConfig: {
    description: 'Content filtering guardrail',
    contentFilters: {
    hate: {
    inputStrength: 'HIGH',
    outputStrength: 'HIGH'
    },
    sexual: {
    inputStrength: 'HIGH',
    outputStrength: 'HIGH'
    },
    violence: {
    inputStrength: 'MEDIUM',
    outputStrength: 'MEDIUM'
    }
    },
    contextualGroundingFilters: {
    grounding: 0.9,
    relevance: 0.8
    }
    },
    kmsKey: myKmsKey,
    naming: naming
    });
    • description: Optional description for the guardrail
    • contentFilters: Content filter configurations (required)
    • blockedInputMessaging: Custom message for blocked inputs
    • blockedOutputsMessaging: Custom message for blocked outputs
    • contextualGroundingFilters: Grounding and relevance thresholds
    • interventionAlarm: (Optional) Intervention alarm thresholds; requires the alarmSettings construct prop
    • guardrailName, guardrailConfig, kmsKey, naming: the guardrail, its configuration, the KMS key encrypting it, and the resource naming
    • alarmSettings: Notification topic ARN, period, evaluation periods, and optional datapointsToAlarm for the intervention alarms. Required when guardrailConfig.interventionAlarm is set. When alarmNamePattern is set, each alarm name must match it, so the topic's CloudWatch grants cover the alarms

    Each threshold creates one CloudWatch alarm on a Metrics Insights query over the AWS/Bedrock/Guardrails InvocationsIntervened metric, aggregated across every version of the guardrail, DRAFT included:

    • countThreshold: alarm when the number of interventions in one period exceeds this value
    • ratePercentThreshold: alarm when the percentage of guardrail evaluations that intervened in one period exceeds this value (at least 0, below 100). One intervention in a period with a single evaluation is 100%, so on a low-traffic guardrail require several breaching periods with datapointsToAlarm, or use countThreshold

    The period must be a multiple of 60 seconds, and period x evaluation periods must not exceed 3 hours, the window CloudWatch evaluates Metrics Insights alarms over. A period with no evaluations is treated as not breaching.

    • hate: Hate speech detection
    • sexual: Sexual content detection
    • violence: Violence content detection
    • insults: Insult detection
    • misconduct: Professional misconduct detection
    • promptAttack: Prompt injection attack detection. Evaluated on inputs only, so outputStrength must be NONE; any other value is rejected at synth
    • NONE: No filtering in that direction
    • LOW: Minimal filtering
    • MEDIUM: Moderate filtering
    • HIGH: Strict filtering
    • grounding: Threshold for grounding to source material (0.0 to 1.0)
    • relevance: Threshold for relevance to the query (0.0 to 1.0)
    contentFilters: {
    hate: { inputStrength: 'HIGH', outputStrength: 'HIGH' },
    sexual: { inputStrength: 'HIGH', outputStrength: 'HIGH' },
    violence: { inputStrength: 'MEDIUM', outputStrength: 'MEDIUM' }
    }
    contentFilters: {
    hate: { inputStrength: 'HIGH', outputStrength: 'HIGH' },
    sexual: { inputStrength: 'HIGH', outputStrength: 'HIGH' },
    violence: { inputStrength: 'MEDIUM', outputStrength: 'MEDIUM' },
    insults: { inputStrength: 'LOW', outputStrength: 'LOW' },
    misconduct: { inputStrength: 'MEDIUM', outputStrength: 'MEDIUM' },
    promptAttack: { inputStrength: 'HIGH', outputStrength: 'NONE' }
    }
    contextualGroundingFilters: {
    grounding: 0.9, // High grounding requirement
    relevance: 0.8 // High relevance requirement
    }
    • @aws-mdaa/l3-construct
    • @aws-mdaa/cloudwatch-constructs
    • aws-cdk-lib
    • constructs

    Classes

    BedrockGuardrailL3Construct

    Interfaces

    BedrockGuardrailL3ConstructProps
    BedrockGuardrailProps
    ContentFilterConfig
    ContentFilters
    CreateGuardrailInterventionAlarmsProps
    GroundingFilters
    GuardrailAlarmsCommonProps
    GuardrailAlarmsCreatedTopicProps
    GuardrailAlarmSettings
    GuardrailAlarmsExistingTopicProps
    GuardrailInterventionAlarmProps
    NamedGuardrailProps
    SensitiveInformationFilters

    Type Aliases

    GuardrailAlarmsProps
    Strength

    Variables

    DEFAULT_GUARDRAIL_ALARM_EVALUATION_PERIODS
    DEFAULT_GUARDRAIL_ALARM_PERIOD_SECONDS
    GUARDRAIL_ALARM_NAME_PREFIX
    GUARDRAIL_INTERVENTIONS_METRIC
    GUARDRAIL_METRIC_NAMESPACE

    Functions

    createGuardrailInterventionAlarms
    guardrailAlarmName
    guardrailAlarmNamePattern
    guardrailInterventionsQuery
    validateGuardrailInterventionAlarm