Redaction
Redaction is allow, minus the sensitive parts. When PiiLeakageDetector or CredentialExposureDetector finds personal data or a secret in a request, AI.Sentinel replaces each value with a numbered placeholder and lets the call through. The model sees [EMAIL_1_k3f9x2], the user still gets a useful answer, and the real value is put back before the reply reaches the caller.
Redact is not a block. Nothing throws, the call is not quarantined, and a redaction is not counted as a threat.
From 3.0, PiiLeakageDetector and CredentialExposureDetector redact by default. Before 3.0 they used the action of their severity, so a Critical finding could quarantine the call. This line turns redaction off:
services.AddAISentinel(opts => opts.RedactByDefault = false);
It makes PII and credential findings use the action of their severity again, as in 2.x, and nothing is redacted. It does not bring back 2.x detection. See What changed regardless.
What changed regardless
These detection changes apply in 3.0 whatever RedactByDefault is set to, and on every surface: the prompt and response scans, the hook CLIs and the MCP proxy.
PiiLeakageDetectormatches every email address, at Medium severity, with the reasonEmail address detected. Before 3.0 it only matched an address preceded by a capitalised "First Last" name, with the reasonEmail with name detected.CredentialExposureDetectormatches quoted keys and values, such as"password": "hunter2", a private key of any PEM type (EC,OPENSSH,ENCRYPTEDand so on, not onlyRSA),AWS_SECRET_ACCESS_KEY:as well asAWS_SECRET_ACCESS_KEY=, and a quoted YAML value on the line after its key. An unquoted value on the next line no longer matches.- A credential reason names the type only, such as
Credential exposure: API_KEY. Before 3.0 it quoted the first 20 characters of the match, part of the secret.
So if Medium findings block in your setup, a prompt or reply that contains any email address is now blocked: with RedactByDefault = false and OnMedium = Quarantine in an app, and with SENTINEL_HOOK_ON_MEDIUM=Block or SENTINEL_MCP_ON_MEDIUM=Block wherever the hook CLIs and the MCP proxy cannot redact, such as a Claude Code prompt or the arguments of a tool call. See Per surface. With redaction on, the response scan still flags an email address the model writes itself.
There is no option that brings back the 2.x patterns. In an app you can stop the wider matches from blocking with a setting for the detector itself; each applies to every type of personal data it finds, not only email addresses:
services.AddAISentinel(opts =>
{
opts.RedactByDefault = false;
// Log PII findings instead of applying the severity action
opts.Configure<PiiLeakageDetector>(c => c.Action = SentinelAction.Log);
// or: cap the severity of PII findings, or switch the detector off
// opts.Configure<PiiLeakageDetector>(c => c.SeverityCap = Severity.Low);
// opts.Configure<PiiLeakageDetector>(c => c.Enabled = false);
});
The hook CLIs and the MCP proxy have no per-detector setting: choose their SENTINEL_HOOK_ON_MEDIUM and SENTINEL_MCP_ON_MEDIUM with email addresses in mind.
Why
- GDPR Art. 5(1)(c), data minimisation: the model receives only the personal data it needs, and usually it needs none.
- GDPR Art. 25, data protection by design: the safe behaviour is the default.
- EU AI Act Art. 10: the PII and credential detectors do not only detect personal data and secrets, they keep them away from the model. Art. 10 is mainly about the training, validation and test data of high-risk systems, so treat this as a building block, not as compliance on its own.
What the model sees
user: Mail jan@acme.nl and ask him to pay NL91ABNA0417164300. Use api_key=sk-live-9f8e7d6c5b4a.
model: Mail [EMAIL_1_k3f9x2] and ask him to pay [IBAN_1_k3f9x2]. Use api_key=[API_KEY_1_k3f9x2].
- Placeholders have the form
[TYPE_n_tag]. They are numbered per type within one call, starting at 1. - The tag,
k3f9x2above, is drawn at random for every call: a lower-case letter and five lower-case letters or digits. Every placeholder of one call carries the same tag, and another call gets another one. - The same value always gets the same placeholder within a call.
- A credential span masks the value only and keeps the key name, so the model still sees the structure (
api_key=[API_KEY_1_k3f9x2]). A PEM private key is masked from its header to its end marker. - Only placeholders this call created are restored. Anything else stays text: a user typing
[EMAIL_1], a placeholder from an earlier call, or one from an earlier model round trip.
Entity types
| Detector | Types |
|---|---|
PiiLeakageDetector | CREDIT_CARD, SSN, IBAN, BSN, NINO, PASSPORT, TAX_ID, EMAIL, PHONE, DATE_OF_BIRTH |
CredentialExposureDetector | PASSWORD, API_KEY, SECRET_KEY, BEARER_TOKEN, AWS_SECRET, SECRET, TOKEN, PRIVATE_KEY, GITHUB_TOKEN |
SECRET is the value of a key whose last word is secret, such as client_secret, WEBHOOK_SECRET or ClientSecret. TOKEN is the value of a credential token key: access_token, refresh_token, id_token, auth_token, bearer_token, api_token, session_token, private_token and personal_access_token in any case, camelCase such as accessToken and IdToken included, and any name in capitals ending in _TOKEN, such as API_TOKEN. A bare token, next_page_token, max_tokens or the GitHub Actions permission id-token names no credential and is left alone.
A value that only refers to a secret is not one, under any key: a whole ${VAR}, ${{ secrets.X }}, $(cmd) or <placeholder>, an environment lookup such as process.env.X, os.environ[...], getenv(...), ENV[...] or Environment.GetEnvironmentVariable(...), your_… template text, an unquoted comparison such as == "abc", and a type annotation such as access_token: str. A secret that only starts like one of these, such as "=Kx9…" or "<Rt5>Kx9", is still redacted.
A key inside a JSON document that is itself a JSON string, such as a tool's text block, is recognised too, so \"client_secret\": \"…\" is redacted between its escaped quotes and the document still parses. An unquoted value stops at a quote that closes a string, so in ["PATH=/bin","API_TOKEN=x","TZ=UTC"] only x is redacted, while a secret with a quote inside, such as ab"cd, is redacted whole.
Within one call, a value that one detector marks as a secret stays a secret where another detector finds it as another type: an email address used as a password is not restored into tool arguments under its EMAIL placeholder either. The MCP proxy holds to it across calls too, whichever call came first: a PII placeholder for a value it has seen as a secret is not restored. Only a placeholder minted after the secret's placeholder expired or was evicted restores that value again.
PiiLeakageDetector now also matches a bare email address. Before 3.0 it only matched an address preceded by a capitalised "First Last" name. See What changed regardless.
What is redacted
Not only the latest prompt. Without this, a value restored for one turn would go back to the model as history in the next. AI.Sentinel redacts:
- the text of every message in every role, including the system message and earlier turns in the history;
ChatOptions.Instructions, which providers send as a system prompt. It is redacted in a copy of your options, which are never changed;- tool-call arguments and tool results: strings, JSON,
AIContentand serialized objects, including the results of tools the model calls during the call; - hosted tool calls and their results: the arguments of an MCP server tool call (
McpServerToolCallContent), the code of a code interpreter call, the queries of a web search call, and the outputs of their results; - the tool call inside a tool approval request or response, including a hosted call, and the reason of an approval response;
- reasoning text;
- attachments of a text type:
text/*, JSON, XML and any+jsonor+xmltype, NDJSON, YAML, JavaScript and form data.
Not redacted: binary attachments such as images, audio and PDF files, content referenced by URI, image generation calls, which carry no text, tool definitions, and the other ChatOptions fields such as AdditionalProperties. Keep personal data out of those.
Per surface
The in-process chat client sees the whole conversation and rewrites it. The hook CLIs and the MCP proxy can only rewrite what their host lets them rewrite, so each surface redacts a different part. Redaction is on by default in the hook CLIs and the MCP proxy. SENTINEL_HOOK_REDACT=off turns it off in the hook CLIs, and SENTINEL_MCP_REDACT=off turns it off in the MCP proxy. Unset, the proxy follows SENTINEL_HOOK_REDACT. A host that calls HookAdapter or CopilotHookAdapter from the libraries opts in with RedactToolResults = true; see Library callers.
| Surface | What is redacted | Restored | Falls back |
|---|---|---|---|
| In-process client | Everything listed under What is redacted | The reply, tool results, and PII in tool-call arguments; secrets never in tool calls | The response scan, a detector that flags text without spans, and a value that is not a string under a key that names a secret or personal data |
| MCP proxy | Tool results, prompts from prompts/get, and text resources from resources/read | PII placeholders in the arguments of a later tools/call, until SENTINEL_MCP_REDACT_TTL_MIN minutes after their last use, 30 by default; secrets never | Tool-call arguments, blob and non-allowlisted resources, content past the byte budget, and personal data inside a JSON key. A rate-limited scan forwards the content unredacted; a pipeline error blocks, see Pipeline errors |
Claude Code PostToolUse | The tool output, returned as updatedToolOutput | No: the model keeps the placeholders | Personal data inside a JSON key |
Claude Code PreToolUse | Nothing. The placeholder guard denies writes and shell commands that carry a placeholder | No | The tool arguments |
Claude Code UserPromptSubmit | Nothing | No | The prompt |
Copilot postToolUse | The tool result's textResultForLlm, returned as modifiedResult | No | A tool result without a string textResultForLlm |
Copilot userPromptTransformed | The transformed prompt, returned as modifiedTransformedPrompt. Experimental: not yet verified with the Copilot CLI | No | Nothing on the prompt itself |
Copilot preToolUse | Nothing. The placeholder guard applies | No | The tool arguments |
Copilot userPromptSubmitted | Nothing | No | The prompt |
"Falls back" means the detection uses the action of its severity, as described under Fallback. On every surface except the in-process client, a failure of the redaction itself also falls back; see Fail closed.
When the hook CLIs and the MCP proxy redact JSON, such as a tool's output or structuredContent, they redact string values only, and keep every key, number and the nesting as they are.
- A value recognised by its key is redacted. The detectors judge a JSON value the way the scan renders it, together with its key:
"password": "hunter2". The valuehunter2on its own matches nothing, but the pair does, so the value becomes{"password":"[PASSWORD_1_k3f9x2]"}and the key stays. Personal data named by its key, such as{"BSN":"123456789"}, is redacted the same way. When a span covers part of the key, only the part in the value is redacted, so{"Authorization":"Bearer abc"}becomes{"Authorization":"Bearer [BEARER_TOKEN_1_k3f9x2]"}. The in-process client does the same for tool-call arguments, tool results and other JSON it sends to the model. An item of an array and a bare string have no key and are judged on their own. - A value that holds a line break is redacted as a whole, not up to the break.
- A JSON literal under a secret key, a bare
null,trueorfalseas in{"password": null}, names no secret and is not flagged.
Three cases fall back:
- Personal data inside a JSON key is scanned but not redacted, because renaming a key would break the shape of the JSON.
- A value that is not a string under a key that names a secret or personal data, such as the number in
{"password": 12345678}, is flagged but not redacted, because a placeholder in its place would change its type. - A match that spans two members in the scan text, such as one that runs from the value of one member into the next, is flagged but not redacted, because each value is redacted together with its own key only.
MCP proxy
- What is scanned. With redaction on, the proxy redacts the text blocks of a tool result, embedded text resources whose MIME type is in
SENTINEL_MCP_SCAN_MIMES, and the tool result'sstructuredContent. 3.0 did not scan embedded resources orstructuredContentat all, so these can produce findings that 3.0 did not. A value that appears in bothstructuredContentand a text block is counted once per occurrence in theREDACTEDsummary. - The byte budget. Every allowlisted item is redacted whole, however large.
SENTINEL_MCP_MAX_SCAN_BYTESis the scan budget of one tool result or prompt, and of each resource item: content over it is reported asSEC-00, which blocks it under the defaultOnCritical. Until #439 an item that did not fit was forwarded unredacted and partly unscanned, and an oversize resource item was skipped. - Restoring into tool calls. When the agent calls a tool with a PII placeholder the proxy minted earlier in the same run, the tool gets the real value. A placeholder stays restorable until
SENTINEL_MCP_REDACT_TTL_MINminutes after its last use, 30 by default. The proxy holds up to 10,000 placeholders and evicts the least recently used. An expired or evicted placeholder reaches the tool as literal text. Secrets are never restored: the tool gets the placeholder. - Restored values are not scanned. The request scan judges the arguments as the agent sent them, with placeholders. A restored email address sent to an outbound tool is therefore not flagged by the PII detector on the way out. An authorization policy sees the restored arguments and is the control for outbound tools.
- Approvals store real values. With
RequireApproval, the approval store, SQLite included, keeps the restored real arguments, so an approver judges the actual call. - Only
tools/callis restored. A placeholder in the arguments ofprompts/getor in a resource URI stays literal text. - Fallbacks. When a scan is rate limited, the content is forwarded unredacted, as 3.0 forwarded it unscanned, and the proxy logs
reason=rate_limited. When the pipeline throws, the proxy blocks; see MCP proxy → Pipeline errors.
Hook CLIs
- Claude Code gets the redacted tool output as
updatedToolOutput, with anadditionalContextnote that names the redacted types and tells the model not to write placeholders to files or commands. See Claude Code → What each action does. - Copilot gets the redacted text as
modifiedResult. With redaction on, a secret or personal data in a Copilot tool result is now redacted and allowed, where it used to be blocked. WithSENTINEL_HOOK_REDACT=offit is still blocked, as before. - Prompts are not redacted on Claude Code or on Copilot's
userPromptSubmitted, because neither lets a command hook rewrite the prompt. Copilot'suserPromptTransformedcan, and is experimental. See Copilot → Prompt enforcement. - Withheld output. When a
PostToolUsescan blocks, on both hosts and also with redaction off, the output is withheld rather than delivered. For Claude Code, the withheld output keeps the shape of the tool'stool_response: identifier-liketypevalues and empty strings are kept, and every other string becomeswithheld by AI.Sentinel: <reason>. Claude Code rejects an output whosetypechanged and then shows the original, which is whytypeis kept. Copilot gets amodifiedResultwith the withheld text. Copilot requiresresultType: "success"on amodifiedResult, so a result whose originalresultTypewas something else, such asfailure, keeps that status as a prefix of the text:[failure] withheld by AI.Sentinel: <reason>. A redacted result is prefixed the same way. - No restore. A hook process runs once per event and keeps no mapping, so the model works with placeholders for the rest of the session.
Library callers
A HookConfig or CopilotHookConfig you build yourself, including the default one, has RedactToolResults off, so HookAdapter.HandleAsync and CopilotHookAdapter.HandleAsync keep the 3.0 behaviour: a secret in a tool result gives the severity decision, Block by default. FromEnvironment turns redaction on, as the CLIs do, unless SENTINEL_HOOK_REDACT is off. A caller that sets RedactToolResults = true gets Allow with HookOutput.UpdatedToolOutput for a redacted tool result and must deliver that output instead of the original. CopilotHookAdapter.HandleAsync scans a userPromptTransformed prompt without redacting it, because it cannot return a rewritten prompt.
Placeholder guard
Because the hook CLIs cannot restore a placeholder, a placeholder written into a file or a command would replace the real value. The guard denies such calls on PreToolUse:
- on Claude Code, a
Write,Edit,MultiEdit,NotebookEditorBashcall; - on Copilot, a
create,edit,str_replace_editor,apply_patch,bash,powershell,write_bashorwrite_powershellcall;
whose input contains text of the exact placeholder shape, such as [EMAIL_1_k3f9x2]. The guard does not know which placeholders were minted, so ordinary text of that shape is denied too. The deny reason is fixed text and never echoes the input. SENTINEL_HOOK_REDACT=off disables the guard.
Restoring
This section describes the in-process client. For the MCP proxy, see Per surface → MCP proxy.
The response scan runs on the reply as the model produced it, still with placeholders. Restoring happens afterwards, so restored values never trigger a response detection.
| Where | Restored |
|---|---|
| Reply text | Yes |
| Tool results in the returned history | Yes |
| Tool-call arguments for PII | Yes, before the tool runs |
| Tool-call arguments for secrets | Never |
| The call in a tool approval request | PII yes, secrets never, because the call runs once approved |
| Hosted tool calls and their results | As tool-call arguments and tool results |
Streaming works the same way. A placeholder split across chunks ([EMA + IL_1_k3f9x2]) is handled.
To keep placeholders in the reply and in tool calls:
services.AddAISentinel(opts => opts.RestoreRedactedValues = false);
Secrets are not restored into tool calls
A prompt-injected model could try to exfiltrate a pasted key by calling a tool with its placeholder. So [API_KEY_1_k3f9x2] stays a placeholder in a tool call, and a tool that needs a secret must get it another way (configuration, a vault). Secrets are restored in the reply to the user.
Tool calls
When the model calls send_email(to: "[EMAIL_1_k3f9x2]"), the tool runs with the real address. This works in either builder order: UseAISentinel, UseFunctionInvocation and UseToolCallAuthorization can be added in any order. The order matters for detection, though: findings on tool traffic are judged before the model sees a result or a tool runs only with Sentinel inside the tool loop; see Builder order and tool traffic. Tool-call authorization judges the real values. A tool's exception message is redacted before it can reach the model. InnerException keeps the original for your application, so logging the whole exception logs the original.
With Sentinel placed inside UseFunctionInvocation, every model round trip is a separate Sentinel call with its own tag. A secret placeholder left in a tool call keeps the tag of the round trip that made it, so the next round trip gives the secret another token and the old one stays text. A reply that quotes the old token shows the placeholder to the user. Nothing leaks, and the old token never resolves to another value.
Conversations kept by the provider
Some providers keep the conversation on their side and return a ConversationId, such as the OpenAI Responses API with storage on. The caller, or UseFunctionInvocation, then sends only the new messages, so the model still holds placeholders from earlier calls in its own history. Those carry another tag: they are never restored to a value of the current call, even when the current call numbers another value with the same type and number. When the model repeats one, the user or the tool sees the placeholder, never another person's value.
Configuring
Redact is a SentinelAction, set per detector:
services.AddAISentinel(opts =>
{
// PII and credentials already redact by default in 3.0.
// Quarantine a pasted secret instead of redacting it
opts.Configure<CredentialExposureDetector>(c => c.Action = SentinelAction.Quarantine);
// Log PII findings instead of redacting them
opts.Configure<PiiLeakageDetector>(c => c.Action = SentinelAction.Log);
});
DetectorConfiguration.Action overrides the severity mapping for that detector, so a Critical credential set to Redact is redacted, not quarantined. AddAISentinel throws an ArgumentException when:
OnCritical,OnHigh,OnMediumorOnLowis set toRedact, because only some detectors can redact;Action = Redactis set on an enabled detector that cannot redact. The semantic detectors cannot say where the data is.
When detectors disagree
If any detection's effective action is Quarantine, the call is quarantined and nothing is sent. Otherwise every Redact detection is redacted, and the highest remaining action among the others (PassThrough, Log, Alert) applies as usual. Every other detector, such as prompt injection, judges the redacted text.
Fallback
When redaction is not possible, the detection uses the action of its severity, as before, and its audit summary ends with ; not redacted. That happens:
- in the response scan, because redaction only applies to what goes to the model;
- for tool-call arguments in the hook CLIs and the MCP proxy, which judge a call before it runs and cannot rewrite it;
- for the prompt on Claude Code
UserPromptSubmitand CopilotuserPromptSubmitted, where a command hook cannot rewrite it. Copilot'suserPromptTransformedcan, and is experimental; - for MCP content the proxy does not redact: blob resources and resources whose MIME type is not allowlisted;
- for a non-string value under a key that names a secret or personal data, such as
{"password": 12345678}, on every surface, the in-process client included; - for personal data in a JSON key and a match that spans two JSON members on the hook CLIs and the MCP proxy;
- when a detector flags text without spans.
Fail closed
In the in-process client, if redaction itself fails, the call fails with a pipeline failure. AI.Sentinel never sends unredacted text there because redaction broke.
The hook CLIs and the MCP proxy cannot fail the host's call, so when redaction fails there, the content is scanned unredacted, as in 3.0, and the detections fall back with ; not redacted. The exception is not kept, because its message can carry the value. This fallback is not a pipeline throw: when the pipeline itself throws, the MCP proxy blocks the call, prompt or read.
The mapping is never stored
In the in-process client, the placeholder to value mapping lives in memory for one GetResponseAsync or GetStreamingResponseAsync call. It is never logged, audited, forwarded or put in an exception, and it is not shared across calls. Every request is redacted afresh from your history, which holds the real values, with a new tag, so a placeholder from an earlier turn is text in a later one.
The MCP proxy keeps the PII placeholders it minted in memory for the run, so it can restore them into later tool calls. It keeps no secret values, only a hash of each under a random key drawn at startup, so it can tell when a PII value is also a secret. It holds at most 10,000 entries, drops an entry 30 minutes after its last use by default, and never logs or audits the mapping. The hook CLIs keep no mapping at all.
Audit and notifications
- One informational audit entry per redacting detector per call, with
PolicyCode = "REDACTED",Severity = Noneand a summary of counts only, such asRedacted 1 EMAIL, 1 IBAN. - The entry is in the hash chain and forwarded like any other, so the compliance record is complete. A SIEM sees an informational entry with the
REDACTEDcode. - It never moves the severity tiles, the trend, the risk score, the threat metrics or an alert.
- OpenTelemetry logs it at Information.
- The dashboard shows a "redacted" badge and a "Redacted" filter chip.
- The caller is told through
InterventionAppliedNotificationwithAction = Redactand the counts.ThreatDetectedNotificationdoes not fire for a redaction alone.
A quarantined prompt audits its redactions
When the prompt scan quarantines a call, the REDACTED entries are still written. The prompt was masked, so its redactions are on record, and the entries are counts only as always. Before, a quarantined prompt wrote the detections and no REDACTED entry.
When the inner client throws after a prompt was masked, the entries are written too. So are they when the call is cancelled.
Detections, sessions and cancellation
These middleware fixes shipped together with screening:
-
Every detection is kept on quarantine.
ThreatDetected.DetectionsandSentinelException.PipelineResultcarry every non-clean detection of the scan, with the score of the whole set. Before, only the top one survived.ThreatDetected.Resultis still the representative detection. -
SEC-23 names every PII type. When
PiiLeakageDetectorreports a finding without masking it, the reason lists each type found, at the highest severity among them, such asPhone number and date of birth detected. Before, it named the first hit only. -
SessionIdKeyaccepts aSessionId. Put either a non-blank string or aSessionIdunderSentinelPipeline.SessionIdKeyinChatOptions.AdditionalProperties:var options = new ChatOptions{AdditionalProperties = new() { [SentinelPipeline.SessionIdKey] = new SessionId("ticket-4711") },}; -
The rate limiter keys only on
SessionIdKey. A non-blank string or aSessionIdunderSentinelPipeline.SessionIdKeygives a per-session bucket; without it calls share the__global__key as before.ChatOptions.ConversationIdstill groups the audit but is not a rate-limit key, since with the OpenAI Responses API it is the previous response id and every turn would get a fresh bucket. -
Cancellation is not wrapped. When
CancellationTokenis cancelled and the inner client throwsOperationCanceledException, it reaches the caller as it is. Before, it became a pipeline failure and then anInvalidOperationException.
Policies and approvals see real values
Authorization policies and approval requests receive the real argument values, so an approver can judge the actual call. A user-written policy that puts argument values in its deny reason puts them in the audit. Keep values out of deny reasons.