Skip to content
mentoor

Topic 5 of 6 · 5 min read

Capturing prompt content without leaking data

Goal: Configure trace capture so prompts are redacted or sampled, and spot a span that leaks a secret or personal data.

Treat the tracing backend as another place customer data is stored: capture prompt content only where you need it, redact before it leaves your process, and limit who can read it and for how long.

Check yourself · 1 of 3

Where should redaction of personal data in traces happen?

Choose one answer

Why it matters

The most useful part of a trace is the prompt and the answer. It is also the riskiest. A support bot prompt can hold names, addresses, order details, a pasted password or an API key. If the full text goes into traces, you now have a second copy of it, in a tool with its own users, backups and retention. Privacy law and customer contracts apply to that copy. OWASP lists sensitive information disclosure among its top risks for LLM apps.

How to do it

  1. Decide per environment. Full content in development and staging with fake data. In production, start with content capture off and turn it on for a defined need.
  2. Use the capture switch. OpenTelemetry GenAI makes message content opt-in. Many libraries expose a setting or environment variable. Set it in config, not in code that someone can forget.
  3. Redact before export. Run a masking step in your own process so the secret never leaves it. Cover emails, phone numbers, card numbers, tokens and any field you know is sensitive. A pattern list will miss some things, so combine it with a rule that removes whole fields, such as the system prompt's customer block.
  4. Sample. Keep content for a small share of traces, for all errors, and for traces with negative feedback. Tail sampling decides after the trace finishes, so it can keep the interesting ones.
  5. Set retention. Delete content after a short window. Metadata (timings, token counts, ids) can be kept longer.
  6. Control access. Few people read production content. Log who looks.
  7. Support deletion. With a tenant or user id on the trace, you can find and remove one person's data on request.

Before and after

Before, an exported span:

{
  "gen_ai.input.messages": "My card 4111 1111 1111 1111 was charged twice. Email me at ana@example.com",
  "http.request.header.authorization": "Bearer sk_live_...redacted"
}

After:

{
  "gen_ai.input.messages": "My card [CARD] was charged twice. Email me at [EMAIL]",
  "gen_ai.usage.input_tokens": 41
}

The authorization header is dropped entirely. The token count remains, so cost and latency analysis still work.

What goes wrong

  • Redacting in the backend. The data already left your process.
  • Capturing HTTP headers and tool arguments. Tokens and personal data hide in tool arguments and headers, not only in the prompt.
  • Keeping everything forever. Retention should match the debugging need, not the storage price.

Examples

Spotting the leak

A tool span has tool.arguments = {"email":"ana@example.com","api_key":"sk_live_...redacted"}. The prompt may have been masked, yet the tool call carries both. Redaction must cover tool arguments, not only messages.

A sampling rule

Keep content for 100% of traces with an error, 100% with a thumbs-down, and a small random share of the rest. Metadata is kept for all of them. Debugging has the traces it needs, and most customer text is never stored.

Key points

  • Prompts and answers in traces are a second copy of customer data and need the same care as a database.
  • Keep content capture off in production by default, then enable it for a defined need.
  • Redact inside your own process before export, so secrets never reach the backend.
  • Sample content: keep errors and negative-feedback traces, and a small share of the rest.
  • Set short retention for content, restrict who can read it, and tag traces so one user's data can be deleted.

Common mistakes

  • Turning on full content capture in production and checking it later.
  • Relying on the backend to mask data after it has been sent.
  • Masking messages but exporting tool arguments and headers unchanged.
  • Keeping content traces with no retention limit.

Check yourself · 2 of 3

You need prompts for debugging but want to store as little customer text as possible. What is the best default?

Choose one answer

Check yourself · 3 of 3

A span's prompt text is masked, yet it still holds an API key. Where is it most likely?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic