Skip to content
be-human.ai
← Back to the journal

Human oversight

Redact Personal Data Before AI Agent Logs Are Stored

Where to run PII redaction in an AI agent pipeline, which fields to mask by default, and how to test that masked logs still support audits.

Be Human typographic cover with the title: Redact Personal Data Before AI Agent Logs Are Stored
Conceptual illustration created with AI · Be Human

Run redaction at the earliest point you control: inside the agent runtime, before any log line, trace span or memory record is written to disk or sent to a third party. Add a second pass at the telemetry collector as a safety net, and treat storage level or query time masking as a last resort, because by then the raw personal data already exists somewhere you have to defend, back up and delete on request. The working rule is mask by default, with a short, versioned allow list of fields that may appear in clear text.

Key takeaways

  • Redaction belongs in the agent process, not in the dashboard. Anything that reaches storage unmasked is now part of your retention, breach and deletion obligations.
  • Use a deny by default field policy. Structured logging makes this possible, because you can only allow fields that have names.
  • Keep what an audit actually needs: correlation identifiers, a pseudonymous subject key, tool names, decision outcomes, policy version and approver identity.
  • Test redaction two ways: planted canary records that prove masking fires, and audit drills that prove a reviewer can still answer real questions from masked logs.
  • Write the field policy down, version it, and review it whenever a new tool, channel or vendor is connected.

Where in the pipeline should redaction run?

There are four places redaction can happen, and they are not equivalent.

  • At the source, inside the agent runtime, when the log event or trace span is constructed. This is the only point where raw personal data never leaves the process boundary.
  • At the collector or log shipper, as events pass through on the way to storage. Useful as a backstop, and the natural place to enforce rules across many services at once.
  • At storage ingest, as a transform applied by the logging platform. The vendor has already received the raw payload at this point.
  • At query time, by masking what analysts see. The raw record is still on disk, in backups and in anything that replicated it.

Choose the source as your primary control and the collector as your second. Treat ingest and query masking as access control, not redaction, and say so in your documentation, because conflating the two is how teams end up believing they hold no personal data while their log archive is full of it.

The practical reason to redact at the source is that agent telemetry is unusually rich. A single tool call can carry the user message, the retrieved document chunks, the arguments the model generated, the raw API response and the model's own reasoning text. Observability guidance treats traces, metrics and logs as the three signals you collect, and the generative AI semantic conventions make it explicit that prompts and completions are capturable attributes. That is exactly why the default must be to strip them before they are emitted, not after.

There is also a scope argument. Every store that holds personal data becomes a place you must search when someone asks for deletion, and a place you must preserve under a legal hold. Keeping logs clean narrows both problems considerably. If you operate in Brazil, the same reasoning drives LGPD duties across memory, logs and prompts.

Which fields should you mask by default?

Start from categories rather than regular expressions. Pattern matching on free text is a useful second layer, but it is a poor first layer: it misses names, nicknames, apartment numbers, medication names and the thousand ways a customer identifies themselves in a sentence.

Mask these by default in every agent log, trace and memory write:

  • Direct identifiers: full name, email address, phone number, national identifiers, passport or driver licence numbers, customer account numbers that are also public identifiers.
  • Financial data: card numbers, bank account and routing details, payment tokens that can be replayed, invoice line detail that reveals an individual's purchases.
  • Health, biometric and other sensitive categories, including anything a caller volunteers in a message body.
  • Credentials and secrets: API keys, bearer tokens, OAuth refresh tokens, session cookies, signed URLs.
  • Free text payloads: the raw user message, the model's full completion, retrieved document chunks and the body of email or chat threads.
  • Precise location and device fingerprints, including full IP addresses and exact coordinates.

For each masked field, pick a technique on purpose rather than defaulting to deletion:

  • Drop entirely when the field has no audit value, which is true of most secrets.
  • Replace with a type label, so the log still records that a phone number was present without recording the number.
  • Keyed hash, using a secret salt held outside the logging system, when you need to compare two records without reading either. Unsalted hashes of phone numbers or emails are trivially reversible and should not be treated as redaction.
  • Tokenize through a controlled vault when a small number of authorized people must occasionally resolve the original value. This is powerful and should be access controlled and logged itself.
  • Truncate or bucket, for example last four digits only, first octets of an IP, a date without a time, an amount in a band rather than exact.

What must survive redaction for an audit to work?

A masked log is only worth keeping if a reviewer can still reconstruct what happened. Decide this before you tune the masking rules, not after, because the temptation under pressure is to loosen redaction when an investigation stalls.

Keep the following in clear text:

  • A request or conversation correlation identifier, so events across services can be stitched together.
  • A pseudonymous subject key that maps to the person only through a separate, access controlled mapping. This is what lets you honour a deletion request without reading the log contents.
  • Timestamps, duration and the sequence of steps.
  • Tool name, target system, operation type and the outcome, including error codes.
  • Authorization context: which permission tier the agent was running under, which policy version applied, and whether a human approval was required and granted.
  • Decision metadata: the rule or threshold that fired, the escalation path taken, and a short structured reason code rather than free prose.
  • Integrity markers: a keyed hash of the full input and output, and the byte length of each. Hashes let you later prove that a document someone produces matches what the agent actually processed.

That last item solves most of the apparent conflict between redaction and evidence. You do not need to store a customer's message to prove what the agent received. You need to store a fingerprint of it, plus enough structure to show the path the decision took. The same approach keeps legal holds on agent records workable, because you preserve the chain without preserving an unnecessary copy of someone's personal life.

A step-by-step plan to add redaction to a running agent

1. Inventory the write paths. List every place the agent emits data: application logs, traces, the memory store, prompt caches, queue messages, error reporting, analytics, vendor dashboards and any webhook you send outward. 2. Convert free text logging to structured events. Replace interpolated strings with named fields. Until fields have names, a deny by default policy is impossible to enforce. 3. Write the field policy as a document, not as scattered code. One table of field name, category, treatment, rationale and owner. Version it. 4. Implement redaction as a single shared library used by every emit path, so a new feature cannot accidentally bypass it. Make the default for an unrecognized field name redaction, not passthrough. 5. Add the collector layer rule set as a second net, targeting the high risk patterns: card like digit sequences, email shapes, token prefixes used by your vendors. 6. Separate the pseudonym mapping into its own store, with its own access list and its own retention clock. 7. Set retention per log class. Decision metadata usually needs to live longer than raw trace detail. Shorter retention is often cheaper and safer than more masking. 8. Backfill or expire the old archive. Decide explicitly what happens to logs written before the policy existed, and record that decision. 9. Re-run a pre-launch security review once redaction is live, since changing the logging layer changes the failure modes.

How do you test that masked logs still support audits?

Two test families, run on a schedule rather than once.

Leak tests prove the masking fires:

  • Inject canary values into test traffic: a distinctive fake email, phone, card and token that appear nowhere else. Then search every downstream store for them, including backups, vendor dashboards and error reports.
  • Fuzz the obvious evasions: spaces inside digit runs, unicode lookalikes, values split across two fields, values embedded inside a JSON string inside another field.
  • Test the error paths. Exception handlers and timeout logs are the classic bypass, because they often dump the whole request object.
  • Test prompt injection cases where a crafted input tries to get the agent to echo secrets into its own output, which then lands in your logs.
  • Confirm the pseudonym mapping is not reachable from the same credentials that read logs.

Audit tests prove the masked record is still useful. Give a reviewer a masked log set and three questions they would actually face: what did the agent do for this case and in what order, who or what authorized the risky step, and what evidence shows the input had not been altered. If they cannot answer from the masked logs, the gap is in your retained metadata, not in the redaction. Fix it by adding structured fields, never by unmasking a category. Fold this drill into your sampling audits of agent work so it stays routine.

An illustrative scenario, and the failure modes behind it

Illustrative only. A services company runs a billing support agent. A customer disputes a credit note issued three months ago. The reviewer opens the case and sees the full chain: request identifier, subject key, the retrieval step that pulled two documents (recorded by document identifier and hash, not content), the agent's proposed credit, the rule that routed it to a human because the amount crossed a threshold, the approver, and the final write to the accounting system with its idempotency key. No name, no email, no card digits, no message body. The reviewer resolves the dispute in minutes and can show the regulator exactly which policy version was in force.

The failure modes that would have broken this are mundane:

  • Logging the entire HTTP request object in an exception handler.
  • Putting the customer's email into the span name or the metric label, where masking rules rarely look.
  • Caching prompts that contain the raw conversation, with a retention window nobody set.
  • Sending verbose traces to a vendor whose subprocessors were never reviewed.
  • Writing personal data into the agent's long term memory, which is a separate store with separate rules. Deletion requests reach there too, which is why finding and removing memory entries needs its own procedure.

Who owns this, and where to start

Redaction fails when it is treated as a one time engineering task. It needs a named owner, a versioned field policy, a test suite that runs with every release, and a review trigger whenever a tool or channel is added. Frameworks for AI risk management point in the same direction: documented controls, measured regularly, with accountability attached to a person.

Be Human builds this into the agents it operates. A first engagement defines the role, the memory and tools it needs, approval boundaries and an observable success criterion, and the logging policy is part of that definition rather than an afterthought. Managed operations can include recurring evaluations, permission review, integration maintenance and incident response, which is where canary tests and audit drills are actually run rather than merely planned.

If you are deciding where to begin, take the free Be Human AI diagnostic to find the first task worth handing to an agent.

Frequently asked questions

Is hashing a phone number enough to count as redaction? Not on its own. An unsalted hash of a phone number or an email address can be reversed by brute force in seconds, because the input space is small and predictable. Use a keyed hash with a secret held outside the logging system, rotate the key on a schedule, and treat the hash as pseudonymous data that still deserves access control rather than as anonymous data.

Should we log the prompt and the model output at all? For most business agents, not in full and not by default. Keep the structural facts (which template, which version, which retrieved document identifiers, token counts, hashes of input and output) and keep full text only in a short lived, tightly restricted debug channel that is off in normal operation. If you do enable full text capture for a diagnostic window, record who enabled it, for how long, and confirm it switched off.

What do we do about logs written before the policy existed? Decide deliberately and write the decision down. The usual options are to purge the old archive, to shorten its retention so it ages out, or to move it behind stricter access with a documented justification. Doing nothing is also a decision, and it is the one that will be hardest to explain if a request or an incident arrives.

Does aggressive redaction make debugging impossible? It makes lazy debugging harder, which is usually a net gain. Engineers who cannot read customer content learn to rely on correlation identifiers, structured step records, error codes and reproducible test fixtures. Where a genuine need exists, a controlled tokenization vault with logged access is a better answer than leaving raw data in logs that hundreds of queries can touch.

Your next step

See where an AI agent fits in your company first.

Take the free Be Human AI diagnostic. A few questions about your work show which task to hand to an agent first, what it needs to know and where a person approves.

Be Human editorial guidance. Examples are illustrative unless explicitly attributed. Sources provide background; implementation choices depend on your workflow.

Less busywork. More room for you.

Bring us the work you wish you had time for.

Book a call to try a personalized AI agent free for 7 days ↗Or take the free AI diagnostic →