> ## Documentation Index
> Fetch the complete documentation index at: https://docs.databunker.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Zero-PII gateway for AI agents

> The Databunker Pro Zero-PII gateway masks personal data in every request an AI agent sends to the model, restores it in the streamed answer and in tool calls, and keeps the values in Databunker Pro. No change to the agent or its tools.

[Tokenize LLM prompts](https://docs.databunker.org/pro/howtos/tokenize-llm-prompts.md) shows how an application masks personal data before it calls a model. That works when you own the code that calls the model. Often you do not: the agent is a coding assistant, a vendor product, or a framework that talks to the model provider directly and calls MCP tools on its own.

For that case, Databunker Pro has the **Zero-PII gateway**. The agent's model traffic goes through your API gateway, and the Zero-PII gateway does the masking there:

* **The user** types real names and reads real names.
* **The tools** (MCP servers, databases, APIs) receive real values in their arguments and return real data.
* **The LLM provider** sees only placeholders such as `[PERSON_1]` and `[EMAIL_1]`.
* **Databunker Pro** holds the values, each one an encrypted token.

The agent is unchanged: you point its model base URL at the gateway. The Zero-PII gateway connects through Envoy's external processing (`ext_proc`) protocol, so it works with any API gateway that supports that protocol, such as [agentgateway](https://agentgateway.dev/), as a separate gRPC service.

## What each party sees

A user asks an agent with a BigQuery MCP tool:

```
Summarize the purchases of our customer Michael Johnson.
```

| | What it sees |
| - | - |
| The user | `Summarize the purchases of our customer Michael Johnson.` and later `Purchase summary for Michael Johnson ... contact m.johnson@example.net` |
| The LLM | `Summarize the purchases of our customer [PERSON_1].` and later the tool result with `[ID_NUMBER_1]`, `[EMAIL_1]`, `[PHONE_1]` |
| The LLM writes | `SELECT ... FROM crm.customers WHERE name = '[PERSON_1]'` |
| The BigQuery tool receives | `SELECT ... FROM crm.customers WHERE name = 'Michael Johnson'` |
| Databunker Pro | One token per value, and a session file that maps `[PERSON_1]` to its token, with no personal data in it |

The model still reasons about the data: it knows there is one person, one email and one phone, and which is which. Business data the Zero-PII gateway does not classify as personal, such as products, amounts, dates and cities, reaches the model unchanged, so it can summarize and calculate.

## Architecture

```mermaid theme={null}
flowchart LR
    AG["AI agent<br/>model base URL = the gateway"]

    subgraph GW["API gateway"]
        LLMR["LLM route<br/>/v1/messages"]
        MCPR["MCP route<br/>/mcp"]
    end

    PF["Zero-PII gateway (ext_proc)<br/>request: mask<br/>answer: restore"]
    DB[("Databunker Pro<br/>tokens and session files")]
    API["LLM provider<br/>sees placeholders only"]
    T["MCP servers and tools<br/>real values"]

    AG --> LLMR
    AG --> MCPR
    LLMR <-->|"gRPC ext_proc"| PF
    PF <-->|"tokens, session file"| DB
    LLMR --> API
    MCPR --> T
```

The API gateway sends each model request to the Zero-PII gateway before forwarding it, and each answer before returning it. The MCP route does not go through the Zero-PII gateway: tool calls carry real values, and stay between the agent and your own tools.

## Example: agentgateway

[agentgateway](https://agentgateway.dev/) is an open-source gateway for AI agents, with LLM and MCP routes in one place. Its `extProc` policy sends the LLM route through the Zero-PII gateway, with no change to agentgateway itself:

```yaml theme={null}
binds:
- port: 4000
  listeners:
  - routes:
    - name: llm
      matches:
      - path:
          pathPrefix: /v1/messages
      policies:
        ai:
          routes:
            /v1/messages: messages
            /v1/messages/count_tokens: anthropicTokenCount
        extProc:
          host: 127.0.0.1:9002       # the Zero-PII gateway
          failureMode: failClosed    # never send a request unmasked
      backends:
      - ai:
          name: anthropic
          provider:
            anthropic: {}            # the agent's own API key or login passes through
    - name: mcp
      matches:
      - path:
          pathPrefix: /mcp
      backends:
      - mcp:
          targets:
          - name: bigquery
            mcp:
              host: http://127.0.0.1:3005/mcp
```

* **`ai.routes`** tells agentgateway that the route speaks the Anthropic Messages API, so it forwards requests in that format instead of translating them.
* **`extProc`** calls the Zero-PII gateway for every request and every streamed answer on this route. The MCP route has no `extProc`, so tool calls pass through with real values.
* **`failureMode: failClosed`** rejects the request if the Zero-PII gateway is down.

Then point the agent at agentgateway. For Claude Code:

```bash theme={null}
ANTHROPIC_BASE_URL=http://localhost:4000 CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 \
  claude --mcp-config mcp.json
```

`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS` keeps Claude Code to request fields agentgateway already knows. `mcp.json` lists agentgateway's MCP route:

```json theme={null}
{ "mcpServers": { "bigquery": { "type": "http", "url": "http://localhost:4000/mcp" } } }
```

## One request through the Zero-PII gateway

```mermaid theme={null}
sequenceDiagram
    participant AG as AI agent
    participant GW as API gateway
    participant PF as Zero-PII gateway
    participant DB as Databunker Pro
    participant LLM as LLM provider

    AG->>GW: POST /v1/messages<br/>"Summarize the purchases of our customer Michael Johnson."
    GW->>PF: request headers and body
    PF->>DB: load the conversation's vault
    PF->>PF: mask: Michael Johnson → [PERSON_1]
    PF->>DB: save new values as tokens
    PF-->>GW: masked body
    GW->>LLM: "Summarize the purchases of our customer [PERSON_1]."
    LLM-->>GW: streamed tool call: execute_sql ... WHERE name = '[PERSON_1]'
    GW->>PF: answer chunks
    PF-->>GW: chunks with real values
    GW-->>AG: execute_sql ... WHERE name = 'Michael Johnson'
```

1. **Request.** The Zero-PII gateway reads the whole request and finds the conversation it belongs to. It loads that conversation's vault from Databunker Pro and masks every user message, assistant message, tool call and tool result in it. New values are tokenized with one `TokenCreateBulk` call, and the masked request goes on to the provider.
2. **Answer.** Agents stream, so the Zero-PII gateway restores the answer chunk by chunk, in text and in tool-call arguments. A placeholder split across two chunks (`[PERS` + `ON_1]`) is held back until it is complete. Values inside tool arguments are JSON-escaped, so a restored name never breaks the arguments.

The agent resends the whole conversation on every turn. The Zero-PII gateway caches what it has already masked, so a long conversation costs one detection pass for the new text only.

## The whole agent run

One question can take several model calls, with tool calls in between. Every model call is masked, every answer is restored, and the tools run on real values:

```mermaid theme={null}
sequenceDiagram
    autonumber
    participant AG as AI agent
    participant PF as API gateway + Zero-PII gateway
    participant LLM as LLM provider
    participant BQ as BigQuery MCP tool

    Note over AG,BQ: Model call 1, the user's question
    AG->>PF: "Summarize the purchases of our customer Michael Johnson."
    PF->>LLM: "Summarize the purchases of our customer [PERSON_1]."
    LLM-->>PF: execute_sql: SELECT ... FROM crm.customers WHERE name = '[PERSON_1]'
    PF-->>AG: execute_sql: SELECT ... FROM crm.customers WHERE name = 'Michael Johnson'
    AG->>BQ: SELECT ... FROM crm.customers WHERE name = 'Michael Johnson'
    BQ-->>AG: C-1003, Michael Johnson, m.johnson@example.net, +1 312 555 0187, Chicago

    Note over AG,BQ: Model call 2, the first tool result
    AG->>PF: the conversation plus the customer row
    PF->>LLM: [ID_NUMBER_1], [PERSON_1], [EMAIL_1], [PHONE_1], Chicago
    LLM-->>PF: execute_sql: SELECT ... FROM sales.orders WHERE customer_id = '[ID_NUMBER_1]'
    PF-->>AG: execute_sql: SELECT ... FROM sales.orders WHERE customer_id = 'C-1003'
    AG->>BQ: SELECT ... FROM sales.orders WHERE customer_id = 'C-1003'
    BQ-->>AG: 4 orders with products, amounts and dates

    Note over AG,BQ: Model call 3, the second tool result
    AG->>PF: the conversation plus the orders
    PF->>LLM: the orders, unchanged: they hold no personal data
    LLM-->>PF: "Purchase summary for [PERSON_1], contact [EMAIL_1] ..."
    PF-->>AG: "Purchase summary for Michael Johnson, contact m.johnson@example.net ..."
```

A follow-up question in the same conversation, such as "What was the day of his last purchase?", uses the same vault: Michael Johnson is still `[PERSON_1]`.

## Conversations and sessions

Each conversation has its own vault, so `[PERSON_1]` means one person in one conversation and nothing outside it. The Zero-PII gateway finds the conversation from the agent's session header, or from the session id in the request metadata. Without either, the first user message identifies it.

The vault lives in Databunker Pro, as in [Tokenize LLM prompts](https://docs.databunker.org/pro/howtos/tokenize-llm-prompts.md#how-it-works): one token per value with `unique: true` and a sliding expiry, and a session file that maps the conversation's placeholders to token UUIDs. API gateway and Zero-PII gateway instances keep no state between requests, so you can restart or scale them, and a conversation continues on any instance.

## Telling the model about placeholders

A model that sees `[PERSON_1]` may say the name is "redacted", or refuse to put a placeholder into SQL. The Zero-PII gateway adds a short note at the end of the system prompt:

```
Privacy note: personal data in this conversation is replaced with placeholders such as
[PERSON_1] or [EMAIL_1]. The user and the tools see the real values: each placeholder you
write is replaced with its value before it reaches them. Treat a placeholder as the value
itself and copy it exactly, brackets included, in answers and in tool arguments (SQL, code,
commands). Do not say that values are masked, redacted or hidden.
```

The note goes after the agent's own system blocks, so the agent's prompt-cache breakpoints stay valid. The agent's own system prompt is not masked by default: it holds the agent's instructions, and some providers validate parts of it.

## Failure handling

The API gateway is configured to **fail closed**: if the Zero-PII gateway is not reachable, the model request is rejected instead of being sent unmasked. If Databunker Pro is not reachable, the Zero-PII gateway cannot load or save the vault, and the request fails the same way.

## What this does not protect

Everything in [What this does not protect](https://docs.databunker.org/pro/howtos/tokenize-llm-prompts.md#what-this-does-not-protect) applies, and the gateway adds a few points of its own:

* **Tools see real data.** That is the point, and it means a tool that sends data to a third party sends real data. Put only tools you trust behind the gateway.
* **The model writes queries with placeholders.** A value the model has to change, rather than copy, cannot be restored. For example, `LIKE '%[PERSON_1]%'` works, but splitting a name into first and last name does not.
* **Thinking stays masked.** The provider signs extended-thinking blocks, so the Zero-PII gateway does not restore them. The user may see placeholders there.
* **Images and documents are not scanned.** Only text, tool calls and tool results are masked.
* **Compressed answers are not restored.** The Zero-PII gateway asks the provider for uncompressed answers. If a provider compresses anyway, the answer passes through unchanged and the Zero-PII gateway logs a warning.

## Related

* [Tokenize LLM prompts](https://docs.databunker.org/pro/howtos/tokenize-llm-prompts.md): the same masking inside your own application, placeholders, vault and expiry in detail
* [Format-preserving tokenization](https://docs.databunker.org/pro/concepts/tokenization.md): token types, expiry, bulk operations
* [File vault](https://docs.databunker.org/pro/concepts/file-vault.md): where the session files are stored
* [Access control](https://docs.databunker.org/pro/administration/access-control.md): scoping the Zero-PII gateway's credential


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.