Sensitive Data in LLM Requests
The AI gateway reads each LLM request on the edge before a provider sees it and looks for sensitive data: credentials, payment card numbers, IBANs, Turkish national ID numbers, phone numbers, email addresses and patterns you define. For each type you choose what happens: nothing (Off), the request goes on and is recorded (Flag), or the request is refused with 403 sensitive_data (Block). The same engine masks those types in the request log.
The project sets one policy. A gateway can override it type by type. Decisions are recorded as types and counts, never values.

Where the scan runs
The scan runs in the edge's elchi-ai-gateway process, inside the consumer authorization's model phase. Envoy calls this phase after the AI ext_proc has read the model name and before the router sends the request to a provider.
How Envoy gets the body:
- A gateway whose effective policy flags or blocks at least one type gets a generated per-route resource
elchi-aigw-gw-<gateway>-authz-model(ExtAuthzPerRoutewithcheck_settings.with_request_body:max_request_bytes= the scan bound,allow_partial_message: true,pack_as_bytes: true). The control plane generates it; you never edit it. - This works on gateways with or without consumer keys. A gateway that requires no key gets the model phase for the scan only.
- A gateway whose effective policy has every type Off is not scanned: Envoy does not send its bodies to the authorization.
- The engine is the same module and version in the control plane's Try it preview and on the edges, so the preview shows what an edge does.
What it finds
The built-in types, in the order the Sensitive data tab lists them:
| Category | Type (API name) | UI title | Notes |
|---|---|---|---|
| Credentials | private_key | Private keys (PEM, OpenSSH, PGP) | The key block is parsed. |
| Credentials | aws_access_key | AWS access key IDs | |
| Credentials | openai_key | OpenAI API keys | |
| Credentials | anthropic_key | Anthropic API keys | |
| Credentials | google_api_key | Google API keys | |
| Credentials | github_token | GitHub tokens | |
| Credentials | slack_token | Slack tokens and webhooks | |
| Credentials | stripe_key | Stripe secret keys | |
| Credentials | jwt | JSON Web Tokens | The token is decoded. |
| Credentials | generic_secret | Other secrets (key = high-entropy value, bearer tokens) | Flag only. Block cannot be chosen: a high-entropy value cannot be told from an id. |
| Financial | credit_card | Payment card numbers | Luhn check and an issuer range. |
| Financial | iban | IBANs | Country length and mod-97. |
| Personal | tr_national_id | Turkish national ID numbers (TCKN) | Check digits. |
| Personal | phone | Phone numbers | Validated per country. |
| Personal | email | Email addresses | Domain checked against the public suffix list. |
You can add up to 32 types of your own (see Your own types).
How a value is judged
The engine is built for few false positives. Each candidate goes through these steps:
- Read the request as its API defines it. The engine reads the message text of OpenAI chat and responses requests, Anthropic messages, Gemini contents, completion prompts and embedding inputs. It skips model names, ids, settings and tool schemas (
model,id,tools,functions,response_format,image_url, …). A body that is not JSON is scanned as plain text. - Skip base64 media. A
data:URL whose payload is base64, or a string of 1 KB or more that is nothing but base64, is not read. A value the client base64-encodes itself is not decoded, so it is not found. - Validate. A candidate must pass its type's validator (Luhn and issuer range, IBAN length and mod-97, TCKN check digits, per-country phone rules, the public suffix list, a parsed key, a decoded JWT, a provider key format).
- Score a likelihood from very unlikely to very likely. A naming word nearby raises it (
card,kart,IBAN,TC kimlik,telefonand more, Turkish and other languages included). A JSON key naming the data raises it too. Words such asexample,test,örneklower it. - Drop what no real system holds. Placeholders, sequences, reserved domains (
example.com,*.test) and published test values (cards such as4111…, the published test TCKN) are never reported.
What this means in practice:
- A card number without a naming word reaches possible, which flags. With a naming word ("kartım 4556 …", "card number …") it reaches likely, which blocks under a Block rule.
- A TCKN needs a word naming it (TC, kimlik) to act.
- The same digits failing Luhn are an ordinary number and pass.
Actions
Each type has one action in requests and one log setting.
| Action (UI / API) | In requests | Recorded |
|---|---|---|
Off / off (default) | Not looked for. | Nothing. |
Flag / flag | The request goes on to the provider. | A flagged row in the decision log, naming the types that flagged. |
Block / block | Refused with 403 sensitive_data before any provider sees it. The answer names the types, never the values. A blocked request uses no quota. | A denied row naming the types that blocked. |
Each rule has three more settings:
| UI column | API field | Default | What it does |
|---|---|---|---|
| Acts from | minLikelihood | Flag from possible, block from likely | The likelihood a finding needs before the action applies. Values: very_unlikely, unlikely, possible, likely, very_likely. |
| At least | minCount | 1 | How many findings of the type one request needs (for bulk leaks). Range 1–1000. |
| Masked in log | logMask | on (true) | Mask the type in the request log's content. This applies to every type, also one whose action is Off. |
Rules that decide the outcome:
-
A Block rule that falls short flags. If its findings are below Acts from or below At least, but at least one finding reaches possible, the request goes on and is recorded as flagged. Example: email set to Block with At least 3. Two addresses → flagged, three → blocked.
-
Acts from on a Flag rule can only lower the threshold. A Flag rule flags from possible unless you set
unlikelyorvery_unlikely. Settinglikelyorvery_likelyon a Flag rule does not raise it. -
Acts from on a Block rule sets the block threshold directly.
possiblemakes an unnamed card number block.very_likelyblocks only the surest findings (the rest still flag). -
The configuration warns, and does not refuse:
generic_secretset to block: "generic_secret only flags — a high-entropy value cannot be told from an id, so it never blocks".- A type that blocks from
unlikelyorvery_unlikely: "ordinary numbers and ids will be refused".
The warnings appear as a notice on the AI Gateway page.
Scope: which messages are read
| UI (Messages read) | API scope | Reads |
|---|---|---|
| What the caller sends (user messages, tool results) | user (default) | Everything the caller writes except the model's own turns: user messages, tool results, and also system and developer messages and the top-level system, instructions and systemInstruction. |
| All, system and assistant too | all | All of the above plus the model's turns: assistant messages, Gemini model turns and the responses API's function calls. |
Under user, text that a client presents as an assistant turn is not read. A client chooses its roles, so use all if that matters to you.
The UI label for user names only user messages and tool results. The engine also reads system and developer messages under user, as the table above says.
Your own types
Under Your own types, click Add a type and fill one row:
| Field | API | Rules |
|---|---|---|
Name (placeholder employee_no) | custom[].name | 2–40 characters: a lower-case letter first, then lower-case letters, digits and _. Not a built-in name. Unique. |
Pattern (placeholder EMP-\d{6}) | custom[].pattern | An RE2 regular expression that must not match empty text. |
Keywords (placeholder sicil, personel) | custom[].keywords | Optional. When set, a match counts only if one keyword appears within 64 characters before or after it (case-insensitive). |
| Action | custom[].action | Off / Flag / Block. New rows start as Flag. |
| Masked in the request log | custom[].logMask | On by default. |
A match of a custom type is scored likely, so a Block rule blocks it. You can add at most 32 custom types.
Values never reported
- Values never reported (
allow.values): a test card, a shared demo address. Numbers are compared by their digits only, so4556-7375-…matches4556 7375 …. Text is compared without case. - Email domains never reported (
allow.emailDomains): the domain and all its subdomains, for examplefirma.com.tr.
Together the two lists hold at most 1000 entries, and each entry at most 256 characters.
Project policy and gateway overrides
The project policy lives in the project's AI gateway configuration, which every edge of the project receives. A gateway may override it:
- Built-in types: field by field. Whatever the gateway's rule leaves unset (
action,minLikelihood,minCount,logMask) keeps the project's value. For example, a gateway ruleemail: {logMask: false}keeps the project's action for email. - Custom types: replaced by name, or added.
- Allow lists: the gateway's entries are added to the project's.
scope,maxScanBytes, and each MCP direction: the gateway's value wins when it is set.
Set the project policy (UI)
- Open AI Gateway → Sensitive data. The tab needs a provider first: until one exists it says "Add a provider first: the policy is part of the project's AI gateway configuration."
- In Credentials, Financial and Personal, set each type's In requests to Off, Flag or Block. Optionally set Acts from, At least and Masked in log.
- Optionally add rows under Your own types.
- Under What is read, and what never counts, set Messages read, Read at most (MiB) (0.25–16, empty means 2), On MCP (gateways serving MCP tools), Values never reported and Email domains never reported.
- Optionally paste a sample into Try it (see Verify it).
- Click Save policy. Elchi saves the policy and deploys it to every connected edge of the project. Discard drops your edit.
Only Owners and Admins can edit the policy, use Try it or see Recent decisions. Other project members see the policy read-only.
If someone else saved the policy after you loaded it, the save returns a conflict and a Changed elsewhere dialog opens:
- Load the stored policy drops your edit.
- Keep my edit keeps it, and your next save overwrites theirs.
If only other parts of the providers document changed (providers, limits, prices), the page saves again on its own.
Override on one gateway (UI)
- Open AI Gateway → Gateways, click the gateway, and go to the Sensitive data section.
- Turn on Override the project's policy.
- For each built-in type, choose:
- In requests: Project (inherit), Off, Flag or Block.
- In the log: Project, Mask or Keep.
- If the gateway serves MCP servers, also set MCP tool arguments and MCP tool results: Project, Scan or Skip.
- Click Save and deploy.
The gateway page does not list custom types, scope, scan bound or allow lists. It keeps any of these that a gateway already has. To change them per gateway, use the API.
Set it through the API
All calls take an Elchi session token. See the REST API reference.
Read the policy, its version and the type catalogue:
curl -s "$ELCHI/api/v3/ai-gateway/sensitive?project=$PROJECT" \
-H "Authorization: Bearer $TOKEN"
# {"data":{"policy":{...}|null,"version":12,"types":[{"name":"private_key","category":"credentials","title":"...","flagOnly":...}, ...],
# "likelihoods":["very_unlikely","unlikely","possible","likely","very_likely"]}}
Replace it (Owner or Admin). expected_version is the version you read. It is the providers document's version, so a save of providers, limits or prices also moves it. A stale version gets 409.
curl -s -X PUT "$ELCHI/api/v3/ai-gateway/sensitive" \
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-d '{
"project": "'$PROJECT'",
"expected_version": 12,
"policy": {
"types": {
"credit_card": { "action": "block" },
"iban": { "action": "block" },
"tr_national_id": { "action": "block" },
"email": { "action": "flag" },
"phone": { "action": "flag", "logMask": false }
},
"custom": [
{ "name": "employee_no", "pattern": "EMP-\\d{6}", "keywords": ["sicil"], "action": "block" }
],
"allow": { "values": ["4556 7375 8689 9855"], "emailDomains": ["firma.com.tr"] },
"scope": "user",
"maxScanBytes": 2097152
}
}'
The answer carries the stored policy, its new version and a deploy object for the background deploy job. "policy": null removes the project policy. Gateways then scan only what their own overrides turn on.
Override on one gateway: read it, change sensitive, write it back.
GW=$(curl -s "$ELCHI/api/v3/ai-gateway/gateways/internal?project=$PROJECT" -H "Authorization: Bearer $TOKEN" | jq '.data')
VER=$(echo "$GW" | jq '.version')
BODY=$(echo "$GW" | jq --arg p "$PROJECT" --argjson v "$VER" '
{project: $p, expected_version: $v,
gateway: (del(.version, .created_at, .updated_at, .updated_by)
| .sensitive = {types: {email: {action: "off"}}})}')
curl -s -X PUT "$ELCHI/api/v3/ai-gateway/gateways/internal" \
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" -d "$BODY"
The equivalent configuration that reaches the edges:
spec:
sensitive: # the project (00-providers.yaml)
types:
credit_card: { action: block }
email: { action: flag }
gateways:
- name: internal
sensitive: # this gateway only
types:
email: { action: off }
What the client gets
A blocked request gets an OpenAI-shaped error. SDKs read error.code.
HTTP/1.1 403 Forbidden
content-type: application/json
{"error":{"message":"the request carries sensitive data the gateway guarded does not allow: credit_card; remove it and retry","type":"permission_error","code":"sensitive_data"}}
The scan never lets an unread request through. All refusals:
| Status | code | When | retry-after |
|---|---|---|---|
| 403 | sensitive_data | A type whose rule is Block reached its likelihood and count. | — |
| 503 | sensitive_scan_busy | The scan could not start: every scan slot or the shared byte budget stayed taken until the check's time ran out. | 1 |
| 503 | sensitive_scan_incomplete | The scan started but was cut short (the check's time ran out, or the client left), and what was read had not already blocked. | 1 |
| 413 | sensitive_scan_too_large | The policy blocks some type and the body is larger than the scan reads (Envoy cut it at maxScanBytes). | — |
| 403 | sensitive_scan_overflow | The policy blocks some type and the body holds more look-alike values than one scan checks (10,000 candidates in one segment, such as decoys placed ahead of a real value). | — |
If the policy only flags, the last two do not apply: a too-large or overflowing request goes on, and if a type flagged in the part that was read, its decision row is marked partial.
Scan bounds and capacity
| Bound | Value | Effect |
|---|---|---|
Scan bound (maxScanBytes, UI Read at most (MiB)) | Default 2 MiB, at most 16 MiB | Envoy sends at most this much of the body. Beyond it nothing is read: where a type blocks, 413 sensitive_scan_too_large; where types only flag, the request goes on unchecked past the bound. |
| Scans at once | GOMAXPROCS × 2 per edge | Further scans wait for a slot while their check lasts. |
| Body budget | 32 MiB of bodies scanned at once per edge | A scan holds about 10× its body in memory. A scan that does not fit waits as for a slot. One body larger than the whole budget runs when nothing else is scanning. |
| Check timeout | 2 s (the generated ext_authz filter's gRPC timeout) | The scan stops when the check ends. The filter does not fail open (failure_mode_allow: false), so a check that does not answer in time never lets the request through. |
| Preview sample | 256 KiB | The Try it / POST /sensitive/test limit. |
Measured cost: a crafted 2 MiB body costs about 30–140 ms of CPU, an ordinary one about 25 ms (Apple M-series).
Where decisions are recorded
Every decision goes to ClickHouse table elchi_ai_gateway_decisions (kept 90 days): every sensitive-data block or flag, and every other authorization refusal. A row holds:
ts, instance_id, project, gateway, consumer, provider, request_model, phase, result (denied|flagged), status, code, findings[], finding_counts[], partial, request_id
findingsholds type names andfinding_countshow many of each. Values are never stored.- A denied row names only the types that blocked. A flag-only type in the same request is not counted as blocked. A flagged row names the types that flagged.
partial = 1means the request was larger than what was read.phase:modelfor LLM requests,mcp/mcp_resultfor MCP traffic.
Rate limit on rows that name nobody: a refusal that names no consumer and no finding (for example 401 invalid_api_key, 503 gateway_not_ready, or a scan refusal on a gateway without keys) is written at most 5 per second per gateway and code, burst 20. The rest are counted in elchi_ai_gateway_decision_rows_suppressed_total{gateway,code}, so a client looping on a bad key cannot fill the table. Every sensitive-data finding is written.
On the edge's loopback /metrics (127.0.0.1:9002):
| Metric | Labels |
|---|---|
elchi_ai_gateway_sensitive_findings_total | gateway, type, action (blocked, flagged) |
elchi_ai_gateway_sensitive_scans_total | outcome: scanned, waited, rejected (→ sensitive_scan_busy), cancelled (→ sensitive_scan_incomplete unless already blocked) |
elchi_ai_gateway_decision_rows_written_total / _dropped_total / _suppressed_total | export health |
In the UI:
- Sensitive data → Recent decisions (Owner/Admin) lists the sensitive-data decisions: requests blocked or flagged for a type, and scan refusals (
sensitive_*). Other refusals, such as a wrong key or a quota, are not listed here. Filters: window, Result (Refused / Flagged), Phase (Model request / MCP arguments / MCP result), Refresh. Columns: Time, Gateway, Consumer ("no key" when none), Phase, Model or tool, Result (Flagged, Blocked, or Denied ·<code>for a scan refusal), and Types (credit_card ×3, plus a partial tag). - Usage shows a Sensitive data figure (blocked count, with flagged and "refused otherwise"), a Sensitive data found card per type, and Refusals by reason. See Usage and costs.
API (Owner/Admin):
curl -s "$ELCHI/api/v3/ai-gateway/decisions?project=$PROJECT&from=2026-12-05T00:00:00Z&sensitive=1&result=denied&type=credit_card&limit=100" \
-H "Authorization: Bearer $TOKEN"
Parameters:
from/to: RFC 3339. The default window is the last 24 h, the longest 90 days.gateway,consumer.result:deniedorflagged.type: one sensitive-data type among the findings.phase:model,mcp,mcp_resultorkey.sensitive=1: only rows with a finding, or a scan refusal (sensitive_*).limit: default 50, at most 500.offset.
MCP traffic
On a gateway that serves MCP tools, an active policy also scans what agents send to MCP servers (tool arguments) and what the servers send back (tool results). On MCP turns each direction off. See MCP: sensitive data.
Masking in the request log
Gateways whose request log keeps content (level Full) mask sensitive data in that content before it is encrypted, with this same policy. Masking follows Masked in log, not the action, so a type that is Off in requests is still masked unless you turn masking off. See Request log.
Rolling it out
- Flag first. Set the types you care about to Flag, project-wide or on one gateway through an override. Nothing is refused yet.
- Watch. For a few days, read Recent decisions (Result: Flagged) and the Sensitive data found card on Usage. Look at which types flag, on which gateways, for which consumers.
- Tune where flags are noise:
- Add known values to Values never reported and internal domains to Email domains never reported.
- Use At least for types that matter only in bulk.
- Paste real (non-secret) samples into Try it to see the likelihood and the reasons.
- Block the types that must never leave. Start with one gateway (override Block) and keep the rest on Flag.
- Watch the refusals. Blocks show as Blocked in Recent decisions. A rise in
sensitive_scan_too_largemeans real requests exceed Read at most. Raise it (up to 16 MiB) or accept the refusals.
Verify it
Before saving: paste a prompt or a whole request body into Try it. Choose As the project's policy or As gateway <name>, then click Try it. The settings on the page run on the sample (saved or not), exactly as an edge runs them. The answer is one of these:
- Blocked:
<types> - Flagged:
<types> - Goes through
- plus Only the first part was read. when the sample was cut
A table lists every match: Type, Where (a JSON path or the text offset), Likelihood and Why (the reasons). The sample is shown with the matches marked. Every type is looked for, including Off ones, so you see what each type would find. The sample is neither logged nor audited, and the answer never contains the values.
curl -s -X POST "$ELCHI/api/v3/ai-gateway/sensitive/test" \
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-d '{"project":"'$PROJECT'","gateway":"guarded","text":"kartım 4556 7375 8689 9855 ile öde"}'
# {"data":{"findings":[{"type":"credit_card",...,"count":1,"max":4,"action":"block"}],
# "matches":[{"type":"credit_card","start":...,"end":...,"likelihood":4,"reasons":[...]}],
# "action":"block","blocked":["credit_card"]}}
likelihood and max are numbers: 1 = very unlikely … 5 = very likely. gateway and a draft policy are optional.
After saving: send a request through the gateway. Use a Luhn-valid card number that is not a published test card, next to a naming word:
curl -s https://ai.example.com/v1/chat/completions \
-H "Authorization: Bearer sk-elchi-..." -H "Content-Type: application/json" \
-d '{"model":"gpt-4o","messages":[{"role":"user","content":"kartım 4556 7375 8689 9855 ile öde"}]}'
# 403 {"error":{...,"code":"sensitive_data"}}
Then check these:
- Recent decisions shows a Blocked row with
credit_card. - The same digits with the last one changed (failing Luhn) get
200. - The edge applies a saved policy within seconds of the deploy. Retry for up to a minute.
- On the edge,
curl -s 127.0.0.1:9002/metrics | grep sensitive_shows the counters moving. - In the edge Envoy's
/config_dump, the gateway's route carries anExtAuthzPerRoutewith"with_request_body","pack_as_bytes": trueand"allow_partial_message": true.
Troubleshooting
| Symptom | Cause | What to do |
|---|---|---|
| A card number goes through, flagged, not blocked | An unnamed card reaches only possible; Block acts from likely. | Expected. Set Acts from to possible on credit_card to block unnamed cards too (more false positives), or rely on the naming word. |
| Nothing is scanned on a gateway | The gateway's effective policy has no Flag or Block type (an override set them Off), so Envoy sends no body. | Check the gateway's Sensitive data section and the project policy. |
generic_secret never blocks | It is flag only by design. | Use a custom type with a precise pattern for secrets you can describe. |
Large prompts get 413 sensitive_scan_too_large | The policy blocks a type and the body is over Read at most. | Raise it (up to 16 MiB), or have clients send smaller requests. |
Bursts of 503 sensitive_scan_busy | The edge is out of scan slots or byte budget within the 2 s check. | Clients should honour retry-after: 1. Add CPU to the edge or spread the traffic. |
| A value you allow-listed still flags | Allow values are compared by digits (numbers) or without case (text). A different value of the same type is not covered. | Add each exact value, or use Email domains never reported for addresses. |
| Recent decisions is empty although requests were refused | The table is written through ClickHouse. Refusals that name no consumer and no finding are rate-limited. | See Usage and costs → When ClickHouse is down and the decision_rows_* metrics. |
Related: Request log · Consumers and keys · Error codes · Security model