Skip to content
mentoor

Topic 5 of 5 · 5 min read

Keeping secrets and personal data out of traces

Goal: Review a trace export, find the fields that leak secrets or personal data, and choose redaction and retention rules.

A trace is a copy of everything your agents saw, so treat the trace store like a database of customer data and redact before you write. Prompts, tool arguments and tool results are usually the most sensitive text in the system.

Check yourself · 1 of 3

Why are traces of agent runs a privacy risk?

Choose one answer

Why it matters

Agents read emails, tickets, files and API responses. Tracing records them. Now a debugging tool holds names, addresses, order histories and sometimes API keys, and it is open to many more engineers than the production database. OWASP lists sensitive information disclosure among the main risks of LLM applications, and a trace store is one place it happens. Some agent SDKs let you turn off capture of generation and tool payloads; use that where you can.

Where leaks hide

  • Prompts and replies: user messages, pasted documents, system prompts with internal rules.
  • Tool arguments and results: database rows, email bodies, file contents.
  • Headers and config: authorisation headers, bearer tokens, connection strings captured with a request.
  • Error messages and stack traces: they often echo the input that failed.
  • Attributes you added: a user email as a span attribute for convenience.

Controls, in order of strength

  1. Do not capture. Record sizes, hashes and ids instead of bodies for the riskiest fields.
  2. Redact at the source. Run a scrubber before the span is exported, not in the backend. Mask key patterns and known personal fields.
  3. Sample. Keep all failed runs and a small share of successes. Less stored data is less exposed.
  4. Limit retention. Set a short expiry for bodies and a longer one for numbers such as tokens and latency.
  5. Control access. Restrict who can open full payloads and log who does.

Before and after

Before, a tool span exports this:

{
  "name": "execute_tool crm.get_customer",
  "attributes": {
    "tool.args": "{\"email\": \"dana.reyes@example.com\"}",
    "http.request.header.authorization": "Bearer sk_live_...redacted",
    "tool.result": "{\"name\": \"Dana Reyes\", \"phone\": \"+1 555 0100\"}"
  }
}

After the scrubber:

{
  "name": "execute_tool crm.get_customer",
  "attributes": {
    "tool.args_hash": "3f9c1a",
    "tool.result_bytes": 214,
    "customer.id": "c_4412"
  }
}

The trace still shows which customer record was used and how large the result was, with no personal text.

What goes wrong

  • Redacting in the backend only. The data already crossed the network and sits in queues and logs.
  • Pattern masks that miss. A key regex catches known formats but not a password in free text.
  • Keeping everything forever because storage is cheap.
  • Debug mode left on in production, capturing full bodies.

Examples

The stack trace leak

A tool raises ValueError: invalid address 'Dana Reyes, 12 Mill Road'. The error message is stored on the span, so a customer's address is now in the trace store. The scrubber should replace exception messages for tools that handle personal data with the exception type and a short code.

A retention split

Keep span timings, token counts and status for 90 days to track cost and failures. Keep full prompt and tool bodies for 7 days, readable only by the on-call group. Debugging an old issue then uses the numbers, not stale personal text.

Key points

  • A trace stores prompts, tool arguments and results, so it holds the same sensitive data as the systems the agents read.
  • Redact or drop sensitive fields before export; backend-only masking is too late.
  • Record ids, hashes and sizes in place of bodies where you only need to correlate.
  • Keep all failed runs, sample the rest, and set short retention for payload bodies.
  • Restrict and audit access to full payloads, and switch off debug capture in production.

Common mistakes

  • Redacting only in the tracing backend, after raw data has already left the service.
  • Adding user email or name as a span attribute just to make searching easier.
  • Relying on a single regex for keys and assuming nothing else sensitive is in free text.
  • Leaving full-body capture on in production after debugging a problem.

Check yourself · 2 of 3

Where should redaction of personal data in spans happen?

Choose one answer

Check yourself · 3 of 3

You need to join a trace to a customer record but must not store their email. What should the span carry?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic