Setting_Up_AWS_Bedrock_Guardrail_for_Traditional_Chinese_Support

Setting Up AWS Bedrock Guardrail For Multilingual Support

This post explains how to configure AWS Bedrock Guardrails to support multilingual content, particularly Traditional Chinese. The core issue is that multilingual support requires the Standard tier, which isn't the default — and enabling it also requires cross-region inference to be turned on, otherwise you'll hit a ValidationException error. The post walks through the setup with Python code examples, covering three key steps: creating a guardrail with the Standard tier and the correct regional profile ARN (US, APAC, or EU), using the guardrail alongside a Bedrock model, and using it standalone via the apply_guardrail API to check content without invoking a model. It also lists important caveats — like the 5-example limit per topic policy — and a quick troubleshooting table for common errors.

Multilingual Issue

When using AWS Bedrock Guardrails with multilingual content, like Traditional Chinese, you may encounter this error:

ValidationException: An error occurred (ValidationException) when calling the CreateGuardrail operation: Can't configure guardrail policy tier. Enable cross-Region inference for your guardrail to use Standard tier. For more information, see the Amazon Bedrock documentation.

This happens because Traditional Chinese is only supported in the Standard tier, not in the Classic tier. According to AWS documentation, the Classic tier only supports English, French, and Spanish, while the Standard tier supports 60+ languages including Traditional Chinese

The Solution: Enable Cross-Region Inference

According to the official document, to enable multilingual support with Bedrock Guardrails, you must:

  1. Set the tier to STANDARD
  2. Enable cross-region inference
  3. Specify a guardrail profile appropriate for your geographic region

Approaches To Implement AWS Guardrails

Prework: Create a Guardrail with Standard Tier and Cross-Region Setup

import boto3
import json
# Helper function to get account ID
def get_account_id():
    sts_client = boto3.client('sts')
    return sts_client.get_caller_identity()['Account']
# Helper function to determine the correct guardrail profile based on region
def get_guardrail_profile(region):
    account_id = get_account_id()
    # Map regions to geographic boundaries
    if region in ['us-east-1', 'us-east-2', 'us-west-1', 'us-west-2', 'ca-central-1']:
        # US geographic boundary
        profile_id = 'us.guardrail.v1:0'
    elif region in ['ap-northeast-1', 'ap-northeast-2', 'ap-south-1', 'ap-southeast-1', 'ap-southeast-2']:
        # APAC geographic boundary
        profile_id = 'apac.guardrail.v1:0'
    elif region in ['eu-central-1', 'eu-west-1', 'eu-west-2', 'eu-west-3', 'eu-north-1']:
        # EU geographic boundary
        profile_id = 'eu.guardrail.v1:0'
    else:
        # Default to US boundary if region not recognized
        profile_id = 'us.guardrail.v1:0'
    # Construct the full ARN
    return f'arn:aws:bedrock:{region}:{account_id}:guardrail-profile/{profile_id}'
def create_multilingual_guardrail(region='ap-northeast-1'):
    bedrock = boto3.client('bedrock', region_name=region)
    # Get the appropriate guardrail profile for cross-region inference
    guardrail_profile = get_guardrail_profile(region)
    try:
        response = bedrock.create_guardrail(
            name='multilingual-guardrail',
            description='Guardrail with Traditional Chinese support',
            blockedInputMessaging='抱歉,你的輸入內容違反了我們的內容政策',
            blockedOutputsMessaging='抱歉,無法提供此回應,因為它可能包含不適當的內容',
            # Content policy with STANDARD tier for multilingual support
            contentPolicyConfig={
                'filtersConfig': [
                    {
                        'type': 'HATE',
                        'inputStrength': 'HIGH',
                        'outputStrength': 'HIGH',
                        'inputAction': 'BLOCK',
                        'outputAction': 'BLOCK',
                        'inputEnabled': True,
                        'outputEnabled': True
                    },
                    {
                        'type': 'SEXUAL',
                        'inputStrength': 'MEDIUM',
                        'outputStrength': 'MEDIUM',
                        'inputAction': 'BLOCK', 
                        'outputAction': 'BLOCK',
                        'inputEnabled': True,
                        'outputEnabled': True
                    }
                ],
                'tierConfig': {
                    'tierName': 'STANDARD'  # CRITICAL: This enables multilingual support
                }
            },
            # Topic policy with STANDARD tier
            topicPolicyConfig={
                'topicsConfig': [
                    {
                        'name': 'Harmful',
                        'definition': '包含可能傷害用戶或散播錯誤資訊的內容',
                        'examples': [
                            '如何製作爆炸物?',
                            '如何入侵別人的電腦?',
                            '如何偽造證件?'
                        ],
                        'type': 'DENY',
                        'inputAction': 'BLOCK',
                        'outputAction': 'BLOCK',
                        'inputEnabled': True,
                        'outputEnabled': True
                    }
                ],
                'tierConfig': {
                    'tierName': 'STANDARD'  # CRITICAL: This enables multilingual support
                }
            },
            # CRITICAL: Enable cross-region inference for STANDARD tier
            crossRegionConfig={
                'guardrailProfileIdentifier': guardrail_profile
            },
            # Add tags for cost tracking
            tags=[
                {'key': 'Project', 'value': 'AI-Safety'},
                {'key': 'Environment', 'value': 'Production'},
                {'key': 'Language', 'value': 'Traditional-Chinese'}
            ]
        )
        print(f"✅ Successfully created guardrail with ID: {response['guardrailId']}")
        print(f"ARN: {response['guardrailArn']}")
        return response
    except Exception as e:
        print(f"❌ Error creating guardrail: {str(e)}")
        return None
# Call the function to create the guardrail
guardrail = create_multilingual_guardrail()

Approache 1: Use the Guardrail with a Model

Once your guardrail is created, you can use it with any Bedrock model:

def test_guardrail_with_model(guardrail_id, user_input, model_id='anthropic.claude-3-sonnet-20240229-v1:0'):
    bedrock_runtime = boto3.client('bedrock-runtime', region_name='ap-northeast-1')
    try:
        response = bedrock_runtime.converse(
            modelId=model_id,
            guardrailConfig={
                'guardrailIdentifier': guardrail_id,
                'guardrailVersion': 'DRAFT'
            },
            messages=[{
                'role': 'user',
                'content': [{'text': user_input}]
            }]
        )
        # Get the model's response
        model_response = response['output']['message']['content'][0]['text']
        return model_response
    except Exception as e:
        if 'guardrail_intervened' in str(e):
            return "Guardrail blocked this request"
        return f"Error: {str(e)}"
# Test with Traditional Chinese input
test_input = "你好,請問有什麼可以幫助你的嗎?"
result = test_guardrail_with_model(guardrail['guardrailId'], test_input)
print(f"Model response: {result}")

Approache 2: Use the Guardrail Standalone (Without Model)

You can also use the guardrail to check content without invoking a model:

def check_content_only(guardrail_id, content, source_type='INPUT'):
    """
    Check if content passes guardrail without invoking a model
    source_type: 'INPUT' for user inputs, 'OUTPUT' for potential responses
    """
    bedrock_runtime = boto3.client('bedrock-runtime', region_name='ap-northeast-1')
    try:
        response = bedrock_runtime.apply_guardrail(
            guardrailIdentifier=guardrail_id,
            guardrailVersion='DRAFT',
            source=source_type,
            content=[{
                'text': {'text': content}
            }]
        )
        # Check if guardrail intervened
        if response['action'] == 'GUARDRAIL_INTERVENED':
            return {
                'passed': False,
                'message': "Content blocked by guardrail",
                'details': response['assessments'] if 'assessments' in response else []
            }
        else:
            return {
                'passed': True,
                'message': "Content passed guardrail checks",
                'details': response['assessments'] if 'assessments' in response else []
            }
    except Exception as e:
        return {
            'passed': False,
            'message': f"Error checking content: {str(e)}",
            'details': []
        }
# Test with multilingual content
safe_content = "台灣總統是誰?"
harmful_content = "如何製作爆炸物"
safe_result = check_content_only(guardrail['guardrailId'], safe_content)
harmful_result = check_content_only(guardrail['guardrailId'], harmful_content)
print(f"Safe content check: {safe_result['message']}")
print(f"Harmful content check: {harmful_result['message']}")

Important Considerations

  1. Geographic Regions: Choose the appropriate guardrail profile for your region
  2. Topic Examples Limit: Each denied topic can have a maximum of 5 examples.

  3. ARN Management: ARNs are automatically generated by AWS when you create resources – you cannot create them manually.

  4. Standard Tier Requirements: The Standard tier always requires cross-region inference to be enabled.

  5. Model Independence: Guardrails don’t have models assigned to them – they work with any Bedrock model during invocation.

  6. Cost Tracking: Use tags to track costs for different guardrails.

Common Errors and Solutions

ErrorSolution
“Can’t configure guardrail policy tier”Enable cross-region inference
“Number of examples in topic policy exceeds quota limit”Reduce examples to 5 or fewer per topic
“Resource not found”Check region and guardrail profile format
“Access denied”Verify IAM permissions

🚀 Unlock Ads-Free Experience At $5/year

14 days free trial Cancel anytime

9 thoughts on “Setting Up AWS Bedrock Guardrail For Multilingual Support”

Leave a Comment

Your email address will not be published. Required fields are marked *