Implementation Guide

Applying Different PII Policies per User Role or Application in a Single LLM Proxy

Treat PII handling as a runtime policy-resolution problem. The proxy first resolves a trusted caller identity (user role, application, or agent), then selects one policy by explicit precedence, then applies an action per entity type and per traffic scope: prompt, response, or tool-call payload. Every decision is written to an audit record that names the policy and version applied, without storing the raw sensitive values.

Why a uniform PII policy fails

A single policy applied to every caller cannot distinguish between user roles, applications, and agents. This guide instead treats PII handling as a runtime policy-resolution problem, in which the proxy decides which policy applies to each request before any action is taken.

Resolve caller identity before anything else

Policy selection is only as reliable as the identity feeding it. Resolve context from signals the proxy can verify, not from fields the client can set freely.

  1. Authenticated credential

    An API key, service credential, or signed token bound to an application. This is the strongest signal for per-application policy.

  2. Token claims

    Role, group, or department claims from a validated JWT. Verify signature and expiry at the proxy before reading any claim.

  3. Agent identity

    For autonomous agents, a distinct identity per agent rather than the identity of the user who launched it.

  4. Request attributes

    Environment, data classification of the route, or declared purpose. Use these as additional attributes for attribute-based access control, not as the sole basis.

  5. Resolved context object

    Normalize all inputs into one context record that the policy engine evaluates and the audit log stores.

Structure the policy model

Each policy applies an action per entity type and per traffic scope. The scopes are prompt, response, and tool-call payload. The available actions are allow, mask, tokenize, block, or log-only.

Set precedence and fail-safe defaults

The proxy matches the resolved context to one policy using explicit precedence and a safe default. Conflicting matches and missing identity are negative paths that should be tested explicitly (see the testing section below).

Account for detection limits in policy design

Detector failure is one of the negative paths a policy design must handle. Verify the behavior of each policy when detection fails, and confirm that the resulting action is the one you intend.

Policy resolution path in one proxy

The four stages below summarize how a single request moves through the proxy.

  1. Step 1Resolve identityDerive user role, application, or agent from verified credentials.
  2. Step 2Select policyMatch context to one policy using explicit precedence and a safe default.
  3. Step 3Enforce actionsAllow, mask, tokenize, block, or log-only per entity type and scope.
  4. Step 4Record evidenceLog the decision and policy version, not the raw data.

Test policies and produce audit evidence

  • Build synthetic test cases for each role, application, and agent, using fabricated PII, and assert both the selected policy and the resulting action.
  • Test negative paths: missing identity, expired token, conflicting matches, and detector failure.
  • Run new or changed policies in log-only mode first and compare outcomes against the current policy before enforcing.
  • Record in each audit entry the request ID, resolved context, policy ID and version, scope, entity types detected, counts, and action taken.
  • Store hashed or tokenized references instead of raw values, and restrict access to the audit store.
  • Review the audit design with your privacy and compliance teams against the GDPR, HIPAA, or NIST AI RMF obligations that apply to you.

Plan runtime PII controls for your shared LLM proxy

Talk through identity resolution, policy precedence, and audit evidence for your applications, roles, and agents.

Talk to an Expert