Kanji
・Cloud engineer / freelance ・Born in 1993 ・From Ehime / Living in Shibuya, Tokyo ・5 years AWS experience Profile details
Table of Contents
bedrock:GuardrailIdentifier
When I began architecting internal enterprise AI tools and multi-agent systems on Amazon Bedrock, my primary focus was security and compliance.
Handling corporate documents and customer information requires stringent safety controls: masking personally identifiable information (PII such as Social Security numbers, credit card details, and phone numbers), blocking competitive mentions, preventing toxic remarks, and thwarting prompt injection attacks. Amazon Bedrock provides an excellent managed safety feature called “Amazon Bedrock Guardrails,” allowing engineers to configure sophisticated filtering policies directly from the console or via IaC.
I established our corporate guardrail, compiled the standard configuration into our internal documentation, and asked all engineering teams: “Please ensure you always include this Guardrail ID and Version in every model invocation call.”
A few weeks later, while auditing AWS CloudTrail events and CloudWatch logs, I uncovered an alarming discovery.
Several Python automated scripts and an open-source AI agent runtime (integrated via MCP servers) deployed by internal teams were invoking foundation models (Claude 3.5 Sonnet / Llama 3) thousands of times directly without specifying any guardrail identifier .
# The unguarded invocation code found in our environment import boto3 bedrock = boto3.client('bedrock-runtime', region_name='us-east-1') # The developer omitted guardrailIdentifier, yet the call succeeded because IAM allowed raw InvokeModel! response = bedrock.invoke_model( modelId='anthropic.claude-3-5-sonnet-20241022-v2:0', body=b'{"prompt": "...", "max_tokens": 1000}' )
The root cause was straightforward: developers occasionally forgot to pass the parameter in boto3 or LangChain wrappers, or third-party agent libraries simply lacked native support for Bedrock Guardrail parameters.
Relying on the “goodwill” of application developers or client libraries inevitably leads to human error, shadow AI usage, and potential bypasses. Guardrails cannot simply be suggested at the client layer; they must be strictly enforced at the cloud infrastructure and IAM access control boundary.
AWS addresses this exact architectural challenge with IAM Policy-Based Enforcement for Amazon Bedrock Guardrails .
▲ Architectural overview: IAM policy evaluation engine mandates Guardrail configuration on incoming inference requests, instantly blocking unguarded calls
The cornerstone of IAM Policy-Based Enforcement is the Amazon Bedrock condition key: bedrock:GuardrailIdentifier .
Historically, IAM policies for Bedrock runtime actions ( bedrock:InvokeModel , bedrock:InvokeModelWithResponseStream , bedrock:Converse , bedrock:ConverseStream ) could only govern whether an identity had permission to call a model resource.
bedrock:InvokeModel
bedrock:InvokeModelWithResponseStream
bedrock:Converse
bedrock:ConverseStream
With bedrock:GuardrailIdentifier , you can enforce that an inference request must carry a specific Guardrail ARN (including its version), or else the call is denied at the IAM layer .
PutEnforcedGuardrailConfiguration
The key advantage of this architecture is financial and operational: unguarded requests are terminated at the IAM engine with a 403 Forbidden before reaching the foundation model , generating zero inference token charges.
Here is the exact IAM policy configuration I implemented in our environments.
The most resilient pattern pairs an Allow statement for foundation model invocations with an explicit Deny statement triggered when the corporate guardrail is missing or mismatched:
Allow
Deny
{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowBedrockInvocation", "Effect": "Allow", "Action": [ "bedrock:InvokeModel", "bedrock:InvokeModelWithResponseStream", "bedrock:Converse", "bedrock:ConverseStream" ], "Resource": "arn:aws:bedrock:us-east-1::foundation-model/*" }, { "Sid": "AllowGuardrailApplication", "Effect": "Allow", "Action": "bedrock:ApplyGuardrail", "Resource": "arn:aws:bedrock:us-east-1:111122223333:guardrail/abc123def456" }, { "Sid": "EnforceMandatoryCorporateGuardrail", "Effect": "Deny", "Action": [ "bedrock:InvokeModel", "bedrock:InvokeModelWithResponseStream", "bedrock:Converse", "bedrock:ConverseStream" ], "Resource": "arn:aws:bedrock:us-east-1::foundation-model/*", "Condition": { "StringNotEquals": { "bedrock:GuardrailIdentifier": "arn:aws:bedrock:us-east-1:111122223333:guardrail/abc123def456:1" } } } ] }
bedrock:ApplyGuardrail
InvokeModel
:1
:2
:DRAFT
StringNotEquals
guardrailIdentifier
In multi-account environments, you can attach a Service Control Policy (SCP) to the organizational root or specific OUs to guarantee compliance across all member accounts. When matching ARN patterns containing wildcards ( * ), always use ArnNotLike (or StringNotLike ) rather than StringNotEquals , and avoid combining it with "Null": {"bedrock:GuardrailIdentifier": "true"} in the same Condition block (since multiple condition operators in one block are evaluated as a logical AND, whereas negated operators like ArnNotLike automatically evaluate to true when the key is absent):
*
ArnNotLike
StringNotLike
"Null": {"bedrock:GuardrailIdentifier": "true"}
true
{ "Version": "2012-10-17", "Statement": [ { "Sid": "EnforceGuardrailAcrossAllAccounts", "Effect": "Deny", "Action": [ "bedrock:InvokeModel", "bedrock:InvokeModelWithResponseStream", "bedrock:Converse", "bedrock:ConverseStream" ], "Resource": "arn:aws:bedrock:*::foundation-model/*", "Condition": { "ArnNotLike": { "bedrock:GuardrailIdentifier": "arn:aws:bedrock:*:*:guardrail/corp-standard-*:*" } } } ] }
In addition to fail-closed request validation via bedrock:GuardrailIdentifier , AWS provides Amazon Bedrock Policies in AWS Organizations and the account-level PutEnforcedGuardrailConfiguration API ( aws bedrock put-enforced-guardrail-configuration ) , which automatically attach baseline guardrails to inference calls even when omitted by the client. Use bedrock:GuardrailIdentifier when workloads must explicitly bind to strict role-specific guardrails (rejecting unconfigured callers with 403), and pair it with PutEnforcedGuardrailConfiguration for organization-wide baseline protection.
aws bedrock put-enforced-guardrail-configuration
Below are the actual verification logs captured via the AWS CLI and boto3.
▲ Corporate Guardrail configuration in the AWS Management Console with PII masking and prompt attack filters
First, we call InvokeModel without specifying any guardrail parameter:
# Invoking Claude 3.5 Sonnet without a guardrail parameter aws bedrock-runtime invoke-model \ --model-id "anthropic.claude-3-5-sonnet-20241022-v2:0" \ --body '{"anthropic_version":"bedrock-2023-05-31","max_tokens":200,"messages":[{"role":"user","content":"Explain our internal deployment guidelines"}]}' \ --cli-binary-format raw-in-base64-out \ response.json
Output (Error Log):
An error occurred (AccessDeniedException) when calling the InvokeModel operation: User: arn:aws:iam::111122223333:user/test-developer is not authorized to perform: bedrock:InvokeModel on resource: arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-3-5-sonnet-20241022-v2:0 with an explicit deny in a service control policy or identity-based policy
The request fails instantaneously with an explicit deny at the IAM layer.
Next, we supply --guardrail-identifier and --guardrail-version :
--guardrail-identifier
--guardrail-version
# Invoking with valid Guardrail ID and Version 1 aws bedrock-runtime invoke-model \ --model-id "anthropic.claude-3-5-sonnet-20241022-v2:0" \ --guardrail-identifier "abc123def456" \ --guardrail-version "1" \ --body '{"anthropic_version":"bedrock-2023-05-31","max_tokens":200,"messages":[{"role":"user","content":"Customer John Doe phone number is 090-1234-5678. Draft a contact note."}]}' \ --cli-binary-format raw-in-base64-out \ response.json cat response.json | jq .
▲ Terminal CLI verification logs: Unguarded calls are blocked immediately by IAM, while guarded calls mask PII entities successfully
Output (Successful Response):
{ "content": [ { "text": "Internal memo created.\n\n[Customer Contact Note]\nCustomer: John Doe\nContact: [PHONE_NUMBER]\n...", "type": "text" } ], "amazon-bedrock-guardrailAction": "INTERVENED", "amazon-bedrock-guardrailIntervention": { "sensitiveInformationPolicy": { "piiEntities": [ { "type": "PHONE", "action": "ANONYMIZED" } ] } } }
The phone number was automatically sanitized to [PHONE_NUMBER] , completing the inference safely.
[PHONE_NUMBER]
Deploying mandatory guardrails across autonomous agent loops and MCP servers yielded several practical lessons.
To measure latency impacts, I conducted a 100-request benchmark using Claude 3.5 Sonnet:
The latency penalty was modest—approximately 50 to 65 ms . In both conversational UIs and multi-step agent loops, this delay is practically imperceptible.
StringLike
["...:1", "...:2"]
As enterprise adoption transitions from early experimentation to widespread autonomous workflows, relying on individual developers to remember security parameters is unsustainable.
Enforcing Amazon Bedrock Guardrails at the IAM boundary with bedrock:GuardrailIdentifier applies established defense-in-depth principles to generative AI. Implementing this condition key across application roles and SCPs permanently eliminates the risk of unguarded invocations.
Real-time AI quant analysis of earnings reports, corporate filings, and momentum indicators for global equities and Japanese stocks.
Master conversation skills with realistic AI phone training and 5-axis feedback. Includes 16-lesson interactive academy and studio AI portraits.
Effortlessly snap receipts for instant AI itemization. Integrated with LINE for seamless group expense tracking and pain-free settlement.
Interactive AI personas (Fortune Teller, Butler, Bartender) host real-time games, challenges, and conversation starters for unforgettable gatherings.
Unbiased healthcare database featuring zero-additive filters and active ingredient cost performance metrics.