Skip to main content

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.

Sensitive data tab Sensitive data tab

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 (ExtAuthzPerRoute with check_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:

CategoryType (API name)UI titleNotes
Credentialsprivate_keyPrivate keys (PEM, OpenSSH, PGP)The key block is parsed.
Credentialsaws_access_keyAWS access key IDs
Credentialsopenai_keyOpenAI API keys
Credentialsanthropic_keyAnthropic API keys
Credentialsgoogle_api_keyGoogle API keys
Credentialsgithub_tokenGitHub tokens
Credentialsslack_tokenSlack tokens and webhooks
Credentialsstripe_keyStripe secret keys
CredentialsjwtJSON Web TokensThe token is decoded.
Credentialsgeneric_secretOther secrets (key = high-entropy value, bearer tokens)Flag only. Block cannot be chosen: a high-entropy value cannot be told from an id.
Financialcredit_cardPayment card numbersLuhn check and an issuer range.
FinancialibanIBANsCountry length and mod-97.
Personaltr_national_idTurkish national ID numbers (TCKN)Check digits.
PersonalphonePhone numbersValidated per country.
PersonalemailEmail addressesDomain 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:

  1. 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.
  2. 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.
  3. 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).
  4. Score a likelihood from very unlikely to very likely. A naming word nearby raises it (card, kart, IBAN, TC kimlik, telefon and more, Turkish and other languages included). A JSON key naming the data raises it too. Words such as example, test, örnek lower it.
  5. Drop what no real system holds. Placeholders, sequences, reserved domains (example.com, *.test) and published test values (cards such as 4111…, 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 requestsRecorded
Off / off (default)Not looked for.Nothing.
Flag / flagThe request goes on to the provider.A flagged row in the decision log, naming the types that flagged.
Block / blockRefused 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 columnAPI fieldDefaultWhat it does
Acts fromminLikelihoodFlag from possible, block from likelyThe likelihood a finding needs before the action applies. Values: very_unlikely, unlikely, possible, likely, very_likely.
At leastminCount1How many findings of the type one request needs (for bulk leaks). Range 1–1000.
Masked in loglogMaskon (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 unlikely or very_unlikely. Setting likely or very_likely on a Flag rule does not raise it.

  • Acts from on a Block rule sets the block threshold directly. possible makes an unnamed card number block. very_likely blocks only the surest findings (the rest still flag).

  • The configuration warns, and does not refuse:

    • generic_secret set 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 unlikely or very_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 scopeReads
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 tooallAll 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.

note

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:

FieldAPIRules
Name (placeholder employee_no)custom[].name2–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[].patternAn RE2 regular expression that must not match empty text.
Keywords (placeholder sicil, personel)custom[].keywordsOptional. When set, a match counts only if one keyword appears within 64 characters before or after it (case-insensitive).
Actioncustom[].actionOff / Flag / Block. New rows start as Flag.
Masked in the request logcustom[].logMaskOn 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, so 4556-7375-… matches 4556 7375 …. Text is compared without case.
  • Email domains never reported (allow.emailDomains): the domain and all its subdomains, for example firma.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 rule email: {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)​

  1. 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."
  2. 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.
  3. Optionally add rows under Your own types.
  4. 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.
  5. Optionally paste a sample into Try it (see Verify it).
  6. 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)​

  1. Open AI Gateway → Gateways, click the gateway, and go to the Sensitive data section.
  2. Turn on Override the project's policy.
  3. For each built-in type, choose:
    • In requests: Project (inherit), Off, Flag or Block.
    • In the log: Project, Mask or Keep.
  4. If the gateway serves MCP servers, also set MCP tool arguments and MCP tool results: Project, Scan or Skip.
  5. 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:

StatuscodeWhenretry-after
403sensitive_dataA type whose rule is Block reached its likelihood and count.—
503sensitive_scan_busyThe scan could not start: every scan slot or the shared byte budget stayed taken until the check's time ran out.1
503sensitive_scan_incompleteThe 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
413sensitive_scan_too_largeThe policy blocks some type and the body is larger than the scan reads (Envoy cut it at maxScanBytes).—
403sensitive_scan_overflowThe 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​

BoundValueEffect
Scan bound (maxScanBytes, UI Read at most (MiB))Default 2 MiB, at most 16 MiBEnvoy 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 onceGOMAXPROCS × 2 per edgeFurther scans wait for a slot while their check lasts.
Body budget32 MiB of bodies scanned at once per edgeA 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 timeout2 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 sample256 KiBThe 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

  • findings holds type names and finding_counts how 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 = 1 means the request was larger than what was read.
  • phase: model for LLM requests, mcp / mcp_result for 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):

MetricLabels
elchi_ai_gateway_sensitive_findings_totalgateway, type, action (blocked, flagged)
elchi_ai_gateway_sensitive_scans_totaloutcome: scanned, waited, rejected (→ sensitive_scan_busy), cancelled (→ sensitive_scan_incomplete unless already blocked)
elchi_ai_gateway_decision_rows_written_total / _dropped_total / _suppressed_totalexport 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: denied or flagged.
  • type: one sensitive-data type among the findings.
  • phase: model, mcp, mcp_result or key.
  • 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​

  1. Flag first. Set the types you care about to Flag, project-wide or on one gateway through an override. Nothing is refused yet.
  2. 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.
  3. 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.
  4. Block the types that must never leave. Start with one gateway (override Block) and keep the rest on Flag.
  5. Watch the refusals. Blocks show as Blocked in Recent decisions. A rise in sensitive_scan_too_large means 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 an ExtAuthzPerRoute with "with_request_body", "pack_as_bytes": true and "allow_partial_message": true.

Troubleshooting​

SymptomCauseWhat to do
A card number goes through, flagged, not blockedAn 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 gatewayThe 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 blocksIt 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_largeThe 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_busyThe 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 flagsAllow 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 refusedThe 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