Contents
Amazon Bedrock AgentCore Gateway interceptors can call Amazon Bedrock Guardrails to mask Japanese My Numbers in MCP tool arguments and results. In the tests presented, interceptor failures halted requests or responses without returning unmasked numbers.
Key Points#
- Guardrails configured for model calls do not inspect tool arguments, results, or definitions.
- Gateway REQUEST and RESPONSE interceptors can mask arguments and results, respectively.
- Japanese identification numbers require custom regular expressions with explicit support for full-width digits.
- Tools that need identification numbers should receive them through an access-restricted path and mask results before returning them to the agent.
Protect the Tool Boundary#
Configuring a Guardrail on a Bedrock Converse request alone leaves a gap in protection. Sensitive information filtering does not evaluate toolUse.input, toolResult, or tool descriptions and schemas. Identification numbers can therefore pass between the model and tools without being inspected by the filter.
Place tools behind AgentCore Gateway and configure Lambda interceptors at both interception points. REQUEST processes arguments before tool execution, and RESPONSE processes results before the agent receives them. This protection applies only to calls routed through the Gateway.
The validation presented used two Lambda tools: get_worker, which returns fictional employee information containing identification numbers, and register_worker, which echoes its arguments. Tool-side logs confirmed that REQUEST masking replaced identification numbers before the registration tool received the arguments.
Configure the Masking Path#
Configure the following components.
1. Create a Guardrail with a custom regular expression for Japanese identification numbers. Explicitly set inputEnabled and outputEnabled to true, and set both actions to ANONYMIZE. The tested interceptor used source="INPUT" for both paths. 2. Grant the interceptor Lambda permission to call bedrock:ApplyGuardrail on that Guardrail. Grant the Gateway permission to invoke the interceptor and target Lambdas. 3. Match the tested configuration by creating an MCP Gateway with IAM authentication and response streaming disabled. 4. Configure interceptors for both REQUEST and RESPONSE. Forward request headers only if the interceptor needs them.
For REQUEST, recursively inspect string values under params.arguments and return transformedGatewayRequest. Returning transformedGatewayResponse at this point skips tool execution. For RESPONSE, inspect text content and values within structuredContent.
Pass methods other than tools/call through unchanged. Tests also confirmed interceptor invocations for initialize and tools/list. Clients using IAM authentication must sign requests with SigV4 and include the negotiated MCP-Protocol-Version header in subsequent requests.
Choose a Policy for Each Tool#
Masking arguments changes what the tool receives. If REQUEST has already replaced an identification number with {JP_MY_NUMBER}, the registration tool cannot save the original number.
| Tool purpose | REQUEST | RESPONSE | |---|---|---| | Document search, report summarization, work record retrieval | Mask | Mask | | Identification number registration, record lookup by identification number | Preserve required identification numbers | Mask |
Use an explicit allowlist with exact tool names for exceptions. Restrict which users and agents can invoke tools that receive raw identification numbers. Response masking cannot protect data already sent to a tool, stored in a database, or written to logs.
The tests presented confirmed this distinction. When REQUEST masking was skipped for register_worker, the tool received the original values, and RESPONSE masking replaced identification numbers in the returned results.
Address Regular Expression and JSON Constraints#
The investigation presented found no dedicated type for Japanese identification numbers in the Guardrails built-in PII list reviewed. Check the latest list before deployment and add custom regular expressions as needed. Include [0-90-9] if full-width digits may occur. [0-9] alone failed to detect the full-width digit examples.
Custom regular expressions do not support lookahead or lookbehind. Expressions that include surrounding characters in a match may remove punctuation or JSON quotation marks during masking. Parse JSON text to extract values, mask those values, and then serialize it again. Nested strings containing additional JSON require separate handling. Store identification numbers as strings to preserve leading zeros.
Regular expressions also match business identifiers with the same format. Across 1,950 synthetic manufacturing-related sentences, the tested regular expression detected every 12-digit order number as a My Number. Overlapping regular expressions generated multiple replacement tags for some values. Do not treat a format match as proof that a value is a My Number; scope masking by tool and field.
Fail Closed and Limit Overhead#
Tests injected four types of failures: an invalid Guardrail ID, insufficient Guardrail permissions, a Lambda timeout, and insufficient interceptor invocation permissions. None returned unmasked identification numbers. REQUEST failures prevented tool execution, while RESPONSE failures blocked results from being returned after tool execution. Reproduce and verify these behaviors in your own deployment.
Catch application exceptions and return a generic JSON-RPC error such as -32603 Internal error. Do not set Gateway exception details to DEBUG in production. Tests showed that this mode exposed stack traces and resource identifiers. Log counts and error types instead of payloads containing sensitive information.
Measured interceptor processing times were approximately 150–420 ms for REQUEST and 130–280 ms for RESPONSE. Making a separate call for each string increases latency and, when built-in PII detection is enabled, billable usage. Test batching and impose a result size limit. In the tests presented, masking approximately 100 KB took about 10 seconds, and processing failed for responses of 2.5 MB or larger.
Next Steps#
Place one tool behind a Gateway configured with both interceptors. Using fictional identification numbers, verify that arguments arrive masked, results are returned masked, and removing ApplyGuardrail permissions blocks the call.
Source: https://zenn.dev/aws_japan/articles/49bf6abcee64bc
Contents
