View a markdown version of this page

Mask sensitive information in requests - Amazon Bedrock AgentCore

Mask sensitive information in requests

A redactInput policy masks sensitive information in a request before the gateway forwards the request to the target. Use it when a model or an MCP tool must not receive values that you send, such as email addresses.

How request masking works

When a request reaches the gateway, Policy in AgentCore runs the guardrail checks of your redactInput policies. A guardrail check is a guardrail in the condition of a policy, such as BedrockGuardrails::SensitiveInformation(["EMAIL"], ["$.messages[-1].content"]). For how to write one, see Writing guardrails in policies. A data path, such as $.messages[-1].content, names the part of the request that the check reads.

Each piece of sensitive information that a check detects is a finding. The gateway replaces each finding with a label in braces and forwards the masked request to the target. The label depends on the check:

  • For an Amazon Bedrock Guardrails sensitive information check, the label is the entity type, such as {EMAIL}.

  • For a third-party check, the label is the category that the policy names, such as {EMAIL_ADDRESS}.

Keep the following in mind when you mask requests:

  • Only the part of the request that the check reads is masked. To pass a specific part of the request to the check, use a data path, such as $.messages[-1].content for the newest message. For more information, see Passing context to your guardrail. If the same value also appears in a part of the request that you haven’t passed to the check, the gateway doesn’t mask it there. For example, an email address in an earlier message of the conversation reaches the target unmasked.

  • The target receives the label in place of the value. For example, if you ask a model to draft a reply to a customer, the draft contains {EMAIL} where your message had the customer’s email address.

  • The gateway rewrites a masked request body as compact JSON. Apart from the masked values, the body has the same content as the one you sent, but its formatting changes. The gateway removes the whitespace between JSON elements and writes 1.50 as 1.5. The order of the fields can also change.

  • You receive no indication that the gateway masked the request. You receive the target’s response to the masked request.

Example policies

Each example names one action and one gateway. Like every guardrail policy, a redactInput policy needs a permit policy for the same action.

Mask email addresses in a chat completion request

The following policy masks email addresses in the newest message of a Chat Completions request:

redactInput( principal, action == AgentCore::Action::"ClaimsChat___POST:/v1/chat/completions", resource == AgentCore::Gateway::"arn:aws:bedrock-agentcore:us-west-2:111122223333:gateway/insurance-gw-a1b2c3d4e5" ) when guardrails { BedrockGuardrails::SensitiveInformation(["EMAIL"], ["$.messages[-1].content"]).count() > 0 };

Suppose that the newest message of your request is the following:

{ "role": "user", "content": "Summarize this complaint from jane.doe@example.com: my claim payment failed twice." }

The model receives the following message:

{"role":"user","content":"Summarize this complaint from {EMAIL}: my claim payment failed twice."}

Mask email addresses in an MCP tool argument

Suppose that your agent opens support tickets with the create_ticket tool, and the ticket system must not store customer email addresses. The following policy masks email addresses in the description argument of the tool:

redactInput( principal, action == AgentCore::Action::"CustomerTools___create_ticket", resource == AgentCore::Gateway::"arn:aws:bedrock-agentcore:us-west-2:111122223333:gateway/insurance-gw-a1b2c3d4e5" ) when guardrails { BedrockGuardrails::SensitiveInformation(["EMAIL"], ["$.description"]).count() > 0 };

Suppose that you call the tool with the following arguments:

{ "description": "The customer jane.doe@example.com reports a failed payment." }

The tool receives the following arguments. The ticket still describes the problem, without the email address:

{"description":"The customer {EMAIL} reports a failed payment."}

For more examples, see Mask sensitive information in a request.

Rules for request masking policies

A redactInput policy follows these rules:

Pair it with a permit policy

A redactInput policy doesn’t authorize a request. Without a permit policy for the same action, the gateway denies the request.

Name the actions of inference and MCP targets

The policy must name its actions and its gateway. If you create a policy for an action of an HTTP target, the policy status becomes CREATE_FAILED. For the error messages, see Rules for interrupt and redact policies.

Use a check that reports where it finds content

Use a check from the redactOutput and redactInput column of Guardrail checks for each effect.

Read the request

Every data path of the check must read the request. Use a JSONPath, such as $.messages[-1].content, or a context.input field path.

Point each data path at one string

Each data path must resolve to a single string. For more information, see Choose data paths for request masking.

Write one policy for each action

Each operation that a target serves is a separate action. For example, InvokeModel and InvokeModelWithResponseStream are different actions. To mask requests for both operations, write a policy for each action. For the action names, see Choose the action for your policy.

Choose data paths for request masking

Choose a data path that resolves to one string in every request. If the API that you call differs from the API that the target serves for the model, the gateway translates your request. Write the data path for the request of the target’s operation. For more information, see Choose the action for your policy.

The following data paths read the text that you send:

OpenAI Chat Completions and Anthropic Messages

$.messages[-1].content reads the newest message of a conversation, when its content is a string.

This path masks only the newest message. Your client keeps the original message in its conversation history, so the next request sends the original value again in an earlier message. To keep the model from receiving the value in later turns, remove the value from the history in your client, or mask it before you add it to the history.

MCP tool calls

A path to the tool argument that holds the text, such as $.description.

The gateway can’t mask a value in the following cases. If the check finds sensitive information in such a value, the gateway denies the request:

  • The data path resolves to several values. For example, $.messages[*].content resolves to several values when a conversation has more than one message.

  • The value isn’t a string. For example, a content field that is a list of content blocks isn’t a string.

  • The value is a string that contains JSON. The gateway doesn’t mask inside such a string. For example, the following description argument holds JSON as text:

    { "description": "{\"customer\":\"jane.doe@example.com\"}" }

When a request can’t be masked

When the gateway can’t mask a finding, it denies the request and doesn’t forward the request to the target. The reason is No policy applies to the request. This is the same reason that you receive when no permit policy applies, and it doesn’t name the redactInput policy. The error depends on the target:

  • Inference targets return HTTP status 403 with the error in the format of the API that you call. For example, an OpenAI API returns the following body:

    {"error":{"message":"Request Denied: Gateway Target request not allowed due to policy enforcement [No policy applies to the request.]","type":"permission_error","code":"403"}}
  • MCP targets return HTTP status 200 with a JSON-RPC error, the error format of MCP. The error code is -32002, or -20001 when the client negotiated MCP protocol version 2026-07-28:

    {"jsonrpc":"2.0","id":7,"error":{"code":-32002,"message":"Tool Execution Denied: Tool call not allowed due to policy enforcement [No policy applies to the request.]"}}

Test request masking in LOG_ONLY mode

A redactInput policy in LOG_ONLY mode never masks a request. The gateway forwards the original request to the target and reports the results of the policy in traces and metrics. For the metrics, see AgentCore generated policy observability data. For more information about testing, see Test a policy in LOG_ONLY mode.