All resources

Preventing PII and secret leakage in AI traffic

AI data-loss prevention is not one regular expression placed in front of a model. Sensitive information can enter through a user prompt, retrieved context, system instructions, uploaded content, or tool results. It can leave through ordinary prose, structured output, streaming chunks, or model-generated tool arguments.

A useful control design starts by mapping those paths and deciding where data should be prevented, detected, transformed, or recorded.

Define the boundary before writing a policy

Document the complete request path:

  1. The application collects user or business data.
  2. An agent may enrich the prompt with retrieved records or tool output.
  3. The governed gateway evaluates the request.
  4. A configured model provider processes the allowed content.
  5. The response returns as text, structured data, or a proposed tool call.
  6. The application may store, display, or execute what it received.

The gateway can govern traffic that passes through it. It cannot protect a provider key that remains embedded in the application, inspect a direct provider connection, or authorize the eventual execution of a tool. Remove bypass credentials and retain application-side authorization for consequential actions.

Classify the data and the action separately

Not every finding should produce the same result. Start with a small taxonomy tied to actual business risk:

  • reusable credentials and tokens;
  • personal identifiers and contact details;
  • regulated or contract-restricted records;
  • internal identifiers that are sensitive only in combination; and
  • model output that could cause a consequential downstream action.

For each class, choose an action by direction and context. A test environment may flag synthetic personal data while a production support workflow blocks credentials and redacts selected identifiers. A broad policy that blocks every number or email address will create false positives and encourage bypass.

Apply controls in layers

The strongest design uses several controls with different purposes:

  • Data minimization: do not place data in the prompt unless the task needs it.
  • Credential isolation: keep provider credentials out of application and agent environments.
  • Request screening: inspect governed input before it reaches a configured provider.
  • Response screening: inspect supported model output before the application consumes it.
  • Tool authorization: validate the user, target resource, operation, and arguments when a tool is actually called.
  • Network controls: restrict direct provider access when the gateway is meant to be the enforcement point.
  • Audit and alerting: record policy outcomes and investigate repeated or unusual findings.

No one layer proves that content is safe. Together, they reduce the paths through which one missed detection becomes a disclosure.

Handle tool-call arguments carefully

A model-generated tool call is a proposal, not authority. Screening can flag or block sensitive arguments before the application sees them, but silently rewriting structured arguments may change the meaning of an operation or produce invalid data.

For consequential tools, prefer a clear allow, flag, or block decision and let the tool service independently authorize execution. The tool boundary should verify the caller, permitted operation, resource scope, and final arguments even when the model request already passed a gateway policy.

Roll out with evidence

Begin with synthetic samples representing the data formats the workload actually processes. Include harmless lookalikes so false positives are visible. Run the policy in a monitoring or flagging mode, review findings with the data owner, and move only well-understood categories to enforcement.

Measure:

  • findings by category, direction, workload, and scope;
  • false-positive and false-negative samples;
  • blocked-request rate and user impact;
  • repeated attempts from one key or application; and
  • policy changes and administrative overrides.

Review the data retained in findings and audit records. Security evidence can itself become sensitive if it stores full prompts indefinitely.

Prepare for detector failure

If a detector or classifier is unavailable, decide whether each workload should fail open or fail closed. A low-risk internal assistant may prioritize availability; a workflow handling restricted records may require denial until screening recovers.

Make that decision explicit, monitor it, and test it. An undocumented fallback during an outage is not a policy.

Production-readiness checklist

Before enforcing an AI data policy
  • Map request, retrieval, response, and tool-execution data paths.
  • Remove direct provider credentials from governed workloads.
  • Define sensitive-data categories with the business data owner.
  • Choose actions separately for request, response, and tool arguments.
  • Test representative positives and harmless lookalikes.
  • Observe findings before enabling broad blocking or redaction.
  • Decide and test fail-open or fail-closed behavior.
  • Restrict who can change policies and review those changes.
  • Set retention rules for prompts, findings, and audit evidence.
  • Keep tool authorization independent from model-output screening.

From policy design to product setup

The objective is a controlled data path with known limitations, not a claim that a detector makes every prompt safe. Use the current PII and secret-leak prevention recipe for the exact Agent Access Manager screens and verification procedure.