How Do You Keep Sensitive Data Out of AI Logs?
How do you redact sensitive data from LLM logs?
To redact sensitive data from LLM logs, allow only approved fields into routine logs and remove sensitive content before sending anything to monitoring or tracing systems. Apply that rule to prompts, tool arguments, tool responses, generated outputs and error traces. Keep operational metadata for investigation, and make access to any necessary diagnostic content a separate, controlled exception.
Start by deciding what a log needs to answer. For most routine investigations, aim to identify which step failed, which configuration ran and whether the request should be retried. Do not make the full conversation the default evidence.
What should routine AI logs contain?
Use a logging allowlist: a defined set of fields that each event may contain. Reject additional fields rather than automatically recording every property attached to a request or response.
Choose fields with a specific investigation purpose:
| Field | Investigation purpose | Recommended boundary |
|---|---|---|
| Random request identifier | Connect events from the same run | Do not derive it from customer data |
| Workflow step | Locate the failure | Use a fixed label, not document text |
| Operation name | Identify the attempted action | Record the action without its arguments |
| Configuration version | Compare behaviour across changes | Keep prompt text out |
| Duration and usage counts | Investigate delays and resource use | Record measurements without content |
| Outcome and error category | Decide what happens next | Use approved categories |
| Redaction result | Check whether the logging policy ran | Record status and rule version only |
Treat this as a starting point, not permission to collect every field. Keep a field only when someone can explain how it supports an operational decision.
Define permitted values as well as permitted names. A field called “status” should accept a small set of outcomes; it should not accept an arbitrary message containing customer text.
Where should redaction happen?
Place the control before each destination that stores or receives diagnostic events. Cleaning up a dashboard after an event arrives is too late for a policy intended to keep that content out of the monitoring system.
Review each boundary separately:
- Prompts: exclude conversation text, attachments and retrieved passages from routine events.
- Tool arguments: record the requested operation and validation outcome without copying submitted values.
- Tool responses: record success, result count or an approved failure category instead of the returned records.
- Generated outputs: record delivery and validation outcomes without copying the answer.
- Errors: convert failures into approved diagnostic fields before reporting them.
Check automatic capture settings as part of the same review. Include request recording, nested trace events, exception reporting and temporary debug logging.
Keep the logging policy separate from the rules governing what the agent may read. What data should an AI agent be able to see? addresses that earlier decision. Data needed to complete a task does not automatically belong in its logs.
How should you combine allowlists and redaction?
Use the allowlist to decide what may leave the application. Use redaction to inspect any permitted text that remains.
Prefer structured fields over free text. For example, record “required field missing” with an approved field label instead of copying the submitted document and explaining what was absent.
For unavoidable text, define the sensitive categories your policy must cover: credentials, contact details, account information, private document content and confidential business terms. Give each category an explicit treatment: remove the value, replace it with a category marker, or exclude the entire field.
Do not approve a redaction policy solely because it recognises familiar formats such as email addresses. Test whether it handles sensitive material expressed as ordinary prose, unexpected structures and nested values.
Set a clear failure rule. If sanitisation cannot complete, send a minimal metadata event or suppress the content-bearing event. Do not fall back to recording the original payload. Decide separately whether the business operation may continue.
What does a useful sanitised event look like?
Consider an illustrative support workflow that reads a customer record and drafts a reply. The draft fails a required-field check.
A proposed raw event might include the conversation, the full customer record, the draft and the exception message. Replace it with a deliberately limited event:
| Detail | Sanitised value |
|---|---|
| Request reference | Random identifier assigned to this run |
| Failed step | Reply validation |
| Operation | Read customer record |
| Tool outcome | Success |
| Validation outcome | Required field missing |
| Content recorded | None |
| Redaction status | Passed |
This event supports a focused investigation: did the retrieval succeed, where did processing stop, and which validation rule rejected the result?
If those fields cannot answer the question, first improve the structured diagnostics. For example, add an approved missing-field label. Do not immediately expand the event to include the whole record.
How should you handle error traces?
Treat errors as another route through the same logging controls. Inspect the actual event sent to the monitoring destination, including nested exception details, attached context and any automatically captured request data.
Use approved error categories for routine reporting. Separate the safe explanation from the underlying exception: “customer lookup unavailable” should not require recording the failed request body.
Keep enough technical context to locate the failing operation, but review it for embedded values. Apply the content policy to retry records and failed background jobs too.
Test unsuccessful paths deliberately. Include malformed input, access denial, tool failure, cancellation and a sanitiser error. A successful request passing the policy does not establish that its error path does.
How can people debug without unrestricted content access?
Create a diagnostic access process before an incident makes broad access tempting.
Require a named investigator, a specific question and a defined scope. Start with sanitised events and synthetic examples. If real content is necessary, approve only the relevant records and fields, with an explicit expiry and deletion step.
Keep exceptional diagnostic captures separate from routine logs. Record who accessed them and why. Apply the same restrictions to copies placed in support tickets, incident notes or shared messages.
Make approval explicit where the workflow involves sensitive records or consequential actions. The approach in human approval steps for AI agents is also useful for deciding who may authorise exceptional diagnostic access.
Review whether the investigation produced a reusable, content-free diagnostic. If it did, add that signal to future events so the next investigation needs less access.
What common mistakes should you avoid?
Recording everything and cleaning it later. Require sanitisation before the event reaches its destination.
Redacting prompts but ignoring responses. Apply the same policy to tool results, generated text and error attachments.
Using partial values without a reason. Prefer a category marker unless the remaining characters serve an approved investigation need.
Replacing identities with stable tokens by default. Decide whether investigators need to connect activity across runs. If they only need to follow one run, use a request-scoped identifier.
Letting debug mode bypass the policy. Make extra capture an explicit exception with an owner and expiry.
Testing only the sanitiser. Also inspect what each destination actually receives. Include exports and alerts in that check.
What should you verify before enabling production logging?
Use a controlled test with synthetic sensitive values:
- Confirm that every event type has an approved field allowlist.
- Insert test values into prompts, tool arguments, responses and outputs.
- Trigger error paths and inspect their attached context.
- Search the receiving systems for the original test values.
- Force sanitisation to fail and verify the fallback.
- Confirm that permitted metadata still supports diagnosis.
- Check access restrictions, retention and deletion.
- Remove temporary diagnostic access after the test.
Make the test capable of detecting leakage: include a controlled comparison that demonstrates the search would find a test value if it were recorded. Treat any unexpected appearance as a failed check.
What are the frequently asked questions?
Should we log complete prompts during a pilot?
Set metadata-only logging as the default. If a pilot needs content review, define the sample, purpose, access and deletion rules separately. Prefer synthetic or explicitly approved material.
Is masking personal information enough?
Do not define the policy around personal information alone. Include credentials, private documents and confidential business information relevant to the workflow.
Should redaction change what the model receives?
Treat these as separate decisions. This logging policy controls what reaches diagnostic systems. Define separately which data the model needs and is permitted to receive.
How do we know whether we removed too much?
Ask an investigator to diagnose a controlled failure using only the sanitised events. Add the smallest approved signal needed to resolve any gap, then repeat the exercise.