

# 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.

**Topics**
+ [How request masking works](#policy-guardrails-redact-input-how)
+ [Example policies](#policy-guardrails-redact-input-examples)
+ [Rules for request masking policies](#policy-guardrails-redact-input-rules)
+ [Choose data paths for request masking](#policy-guardrails-redact-input-paths)
+ [When a request can’t be masked](#policy-guardrails-redact-input-denied)
+ [Test request masking in LOG\_ONLY mode](#policy-guardrails-redact-input-log-only)

## How request masking works
<a name="policy-guardrails-redact-input-how"></a>

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](policy-guardrails-in-policies.md#defining-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](policy-guardrails-in-policies.md#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
<a name="policy-guardrails-redact-input-examples"></a>

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
<a name="policy-guardrails-redact-input-example-chat"></a>

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

```cedar
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:

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

The model receives the following message:

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

### Mask email addresses in an MCP tool argument
<a name="policy-guardrails-redact-input-example-mcp"></a>

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:

```cedar
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:

```json
{ "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:

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

For more examples, see [Mask sensitive information in a request](example-policies-guardrails.md#example-policies-guardrails-redact-input).

## Rules for request masking policies
<a name="policy-guardrails-redact-input-rules"></a>

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](policy-guardrails-streaming.md#policy-guardrails-streaming-authoring).

 **Use a check that reports where it finds content**   
Use a check from the `redactOutput` and `redactInput` column of [Guardrail checks for each effect](policy-guardrails-streaming.md#policy-guardrails-streaming-checks).

 **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](#policy-guardrails-redact-input-paths).

 **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](policy-guardrails-streaming.md#policy-guardrails-streaming-actions).

## Choose data paths for request masking
<a name="policy-guardrails-redact-input-paths"></a>

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](policy-guardrails-streaming.md#policy-guardrails-streaming-actions).

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:

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

## When a request can’t be masked
<a name="policy-guardrails-redact-input-denied"></a>

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:

  ```json
  {"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`:

  ```json
  {"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 name="policy-guardrails-redact-input-log-only"></a>

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](observability-policy-metrics.md). For more information about testing, see [Test a policy in LOG\_ONLY mode](policy-test-a-policy.md).