Skip to main content
The LLM Gateway is in beta.
A data policy controls what happens to the content of requests that pass through the LLM Gateway:
  • Which sensitive data, such as personal information or API keys, the gateway redacts before a request reaches the LLM provider.
  • Whether LangSmith stores request and response bodies in traces.
Administrators use data policies to do the following without changing application code:
  • Keep customer data and credentials that developers or agents put in prompts away from third-party providers.
  • Limit what LangSmith stores.
Like the other gateway policies, a data policy can apply to an organization, a user group, a workspace, a user, or an API key. In the LLM Gateway Policies tab, data policies have the Data protection policy type. Each policy combines three options and a timeout setting:
  • Redact personal information (PII) and Redact secrets: which sensitive data the gateway scans for and redacts before a request reaches the LLM provider. See How redaction works.
  • Store trace content: whether the gateway writes request and response bodies to the LangSmith trace. See Store trace content.
  • If redaction takes too long: how long the scan may run, and whether a request proceeds when that limit is exceeded. See Scan time and timeout behavior.

Availability

Data policies are available to every organization with access to the LLM Gateway. Every such organization can create policies that redact secrets and store trace content. PII redaction requires a separate entitlement, which is off by default and enabled for selected organizations. Without it:
  • The Redact personal information (PII) option appears locked in the create and edit forms, with a Request access link.
  • The If redaction takes too long setting is hidden, and the policy uses the default timeout behavior.
  • The API rejects any policy configured to detect PII.
To enable PII redaction, click Request access or contact your account team.

How redaction works

When a data policy enables detection, the gateway scans outbound requests before they reach the LLM provider. Detected values are replaced with placeholders before the request is forwarded upstream, so the provider only ever sees the redacted payload. For successful responses, the gateway restores the placeholders to the original values before returning the response to the caller. The Redact personal information (PII) and Redact secrets options are independent. On a new policy, PII redaction starts on with every type selected (for organizations that have the entitlement), and secrets redaction and trace content start off.

Redact personal information

The Redact personal information (PII) option covers names, emails, US phone numbers, addresses, and US SSNs. When the option is selected, six types appear beneath it, each selectable on its own, in two groups based on how the gateway detects them. Types under Pattern match (instant) are matched with regular expressions: Types under Model detection (slower) are matched by Presidio:

Redact secrets

The Redact secrets option detects common API keys, tokens, and credentials and redacts them from the request: Detection is deliberately narrow. Only rules anchored to a recognizable token shape are applied, so high-entropy prose in a prompt does not trigger a redaction.

Scan time and timeout behavior

Each data policy caps how long the scanning pipeline may run and decides what happens when that cap is reached. Under If redaction takes too long, set the number of seconds to wait, 2 by default and configurable from 0.1 to 30. Then select what happens when the scan does not finish in time: Allow request unredacted, the default, or Block request. This setting appears only for organizations with the PII redaction entitlement. Elsewhere the policy uses the defaults.

Store trace content

The Store trace content option controls whether request and response bodies are stored in gateway traces. It is off for all organizations, and a data policy turns it on for the requests that policy matches. To store content without redacting anything, create a data policy that selects only Store trace content. When several data policies match a request, the most specific scope decides. If policies at the same scope disagree, content is not stored. With content off, traces still record metadata such as token usage, latency, status, model information, and policy evaluation results. For where gateway traces appear, what metadata they carry, and how trace content affects billing, see View LLM Gateway traces.

Create a data policy

Creating and managing policies requires organization:gateway:manage permission. Selecting a user group also requires organization:user-groups:read; see User Groups for availability and setup.
  1. Go to LLM Gateway and select the Policies tab.
  2. Click + Policy.
  3. Under Policy type, select Data protection.
  4. Enter a Name, or keep the generated one.
  5. Define a Scope and the subjects the policy applies to.
  6. Under What should this policy do, select any combination of Redact personal information (PII), Redact secrets, and Store trace content. For PII, select the types to redact.
  7. (Optional) Under If redaction takes too long, set the number of seconds and what happens when the scan does not finish in time.
  8. Click Create policy.
Data policies apply to all requests that pass through the gateway in the scope where they are configured. They take effect immediately.

How redacted content appears

When PII or a secret is detected, the content is replaced with a placeholder in both the request sent to the provider and the LangSmith trace. For example: Original request:
Upstream redaction:
The gateway prepends the disclaimer so the model treats the placeholders as values it can reuse verbatim. Placeholders follow the format [SAFE_TO_USE:<CATEGORY>_<suffix>]:
  • SAFE_TO_USE: fixed prefix marking the value as a redacted placeholder.
  • <CATEGORY>: the detected type. Examples: PERSON, LOCATION, US_SSN, US_PHONE_NUMBER, OPENAI_API_KEY, GITHUB_PAT, LANGSMITH_PERSONAL_TOKEN.
  • <suffix>: an 8-character tag. A value that appears twice in one request gets the same placeholder both times, and the tags cannot be correlated across requests.
The trace in LangSmith shows the redacted version along with metadata indicating that redaction occurred and which categories were detected. Downstream de-redacted response: When the upstream provider returns a successful response, the gateway replaces the placeholders with the caller’s original values. Streamed responses are rewritten event by event, so de-redaction does not delay the stream. For example, your agent may see this response:

What redaction covers

What it covers:
  • Outbound request content (the message sent to the LLM provider) is scanned and redacted before it leaves the gateway.
  • The redacted version is what appears in LangSmith traces.
  • Placeholders in a successful provider response, streamed or not, are restored to the original values before the response reaches the caller.
What it does not cover:
  • Responses from the LLM provider: if the model generates sensitive data in its response, that content is not scanned or redacted. Only the request is scanned.
  • Provider errors: when the provider returns a status of 400 or above, the gateway passes the body through untouched, so the caller sees the placeholders rather than the original values.
  • Application traces outside the gateway: your application receives the restored values, so its own traces can capture them.
  • Data already in your traces: redaction only applies to requests flowing through the gateway. Traces written directly to the LangSmith API (bypassing the gateway) are not scanned.
  • Platform-level ingestion: if your requirement is to prevent PII from ever entering LangSmith regardless of how it arrives (for example, data residency compliance), gateway redaction alone is not sufficient. That requires ingestion-level redaction, which is a separate capability.
  • System and developer prompts: these are skipped, along with assistant tool-call metadata and tool-call arguments that arrive as a single JSON string. User messages, tool results, and structured tool-call arguments are scanned.
Scanner failures fail open: if a scanner is unreachable or errors, the request continues to the provider with the content that stage produced. Only a scan timeout can block a request, and only when the policy’s timeout action is set to Block request. The coverage boundary matters. If your security model requires that sensitive data never reaches any system (not just the LLM provider), make sure you understand which surface the gateway covers and which surfaces require additional controls.

Next steps