# LLM Security for Coding Agents: Keep Secrets Out of Transcripts

> LLM security for coding agents starts before observability: keep credentials out of prompts, tool results, traces, logs, and transcript stores.

Source: https://last9.io/blog/llm-security-coding-agents-transcripts/

A coding agent often sees the material you would never paste into a normal support ticket: shell output, `.env` fragments, CI logs, kubeconfig hints, failed curl commands, trace attributes, and whatever a tool returned while debugging production. If a long-lived credential lands in that conversation, it may be stored in the transcript and copied into telemetry, log pipelines, evaluation datasets, or provider systems you cannot inspect.

That is the LLM security problem this post handles: keep credentials out of prompts, tool arguments, tool results, traces, logs, and transcript stores without going blind on agent behavior.

The goal is not to stop tracing agents. It is to trace the agent's behavior while treating raw payloads as hazardous by default. [OWASP's LLM Top 10](https://owasp.org/www-project-top-10-for-large-language-model-applications/) lists sensitive information disclosure as a risk for LLM applications, and a [recent public thread](https://news.ycombinator.com/item?id=50527957) put the operational version plainly: long-lived credentials in LLM transcripts are an attack path.

## Why LLM security changes when coding agents touch production

LLM security gets sharper when the assistant can use production-adjacent tools. A chat assistant that answers docs questions sees user prompts. A coding agent debugging an incident may ask for logs, run shell commands, call an MCP tool, inspect traces, and summarize stack traces. Those tools are useful because they return real operational context.

They can also return credentials by accident:

- An error log prints `Authorization: Bearer ...`.
- A shell command echoes `AWS_SECRET_ACCESS_KEY`.
- A tool returns the full request payload instead of a resource ID.
- A trace attribute stores an outbound API key under `http.request.header.authorization`.
- A prompt includes copied config from a developer's terminal.

Traditional observability risk is usually about what lands in your backend. Agents add one more storage system before that: the transcript. Once a secret is in the model conversation, you have to reason about model provider retention, transcript export, tool replay, eval datasets, and every observability backend that records the run.

A safer design starts from a small rule: **metadata capture is on by default; payload capture is off by default.** You should be able to answer which agent ran, which tool it called, how long it took, how many tokens it used, and whether it failed, without storing the raw prompt, completion, tool arguments, or tool result.

## Map the credential path before you add more tracing

Before you turn on richer traces, draw the path a secret could take. Do it as a data-flow map, not as an architecture diagram. The question is: "If an API key appears at this point, where can it be copied next?"

The common path looks like this:

1. **Developer input:** a pasted prompt, terminal output, config snippet, or incident note.
2. **Agent runtime:** prompt assembly, memory, scratchpad, framework callbacks, and local logs.
3. **Model boundary:** provider API, gateway, reseller, or inference endpoint.
4. **Tool boundary:** MCP server, shell tool, ticketing API, cloud API, database, or retrieval system.
5. **Telemetry boundary:** spans, metrics, logs, events, token metrics, and transcript logs.
6. **Backend boundary:** observability storage, trace search, log archive, cold storage, SIEM, and exports.

For each hop, write down three fields: who controls it, whether it stores payloads, and how a credential is deleted or revoked after exposure. If the answer is "we do not know," treat that hop as an external boundary. Minimize what crosses it.

This is also where opaque provider chains matter. You may not see every reseller, gateway, GPU provider, logging subsystem, or observability processor behind a model call. That does not mean you cannot trace the system. It means you should trace metadata around the boundary and keep raw credentials out of the boundary.

## Keep long-lived credentials out of the transcript

The strongest LLM security control is not better redaction. It is preventing durable credentials from entering the conversation in the first place.

Start with credential shape:

- Prefer short-lived credentials with a narrow scope and an expiry measured in minutes.
- Use brokered tool access so the agent asks a service to perform an action instead of receiving a secret.
- Give tools scoped roles: read-only for inspection, one resource or tenant when possible, and no wildcard admin access.
- Return references, handles, and IDs from tools instead of raw tokens or full payloads.
- Block known secret formats at the chat input and tool-output layer.

A broker is often the difference between "the agent saw a credential" and "the agent asked for a task." For example, instead of returning a cloud token to the agent so it can query a resource, expose a tool named `get_deployment_logs(service, window)` and let the tool hold the cloud credential server-side. The transcript records the service name, time window, and result summary, not the credential that made the API call possible.

This design does not remove the need for authorization. The broker should enforce the caller's identity, the agent's allowed actions, and the environment. A production-capable agent should not inherit every permission of the human sitting at the keyboard.

## Instrument the agent, not the secret

Good agent telemetry is mostly metadata. You need enough detail to debug a bad run, compare releases, and find regressions. You do not need to store every byte the agent saw.

For most coding-agent workflows, record these fields by default:

| Category | Capture by default | Keep out by default |
| --- | --- | --- |
| Run identity | Agent name, run ID, conversation ID, release, environment | Full conversation transcript |
| Model call | Provider, model, operation, token counts, latency, finish reason | Prompt body and completion body |
| Tool call | Tool name, status, duration, retry count, error type | Tool arguments and tool result |
| Resource context | Service name, route, trace ID, log fingerprint, resource ID | Authorization headers, raw request bodies, `.env` content |
| Policy | Payload-capture decision, redaction version, rule ID | Secret values used to make the decision |

[OpenTelemetry's GenAI conventions](https://opentelemetry.io/docs/specs/semconv/gen-ai/) define telemetry for model and agent activity, and the MCP conventions cover tool calls. The useful security detail is that payload-like fields are not the same as operational fields. A tool name, duration, retry count, and error type can be safe to retain. `gen_ai.tool.call.arguments` and `gen_ai.tool.call.result` can contain sensitive information, so keep them opt-in.

When you need correlation, use stable references. Store a trace ID, span ID, resource ID, ticket ID, or a hash of the sensitive value. For example, hashing a leaked token lets you search for repeated exposure without copying the token into every query and incident note.

## Redact LLM-specific fields before telemetry leaves your control

Redaction belongs as early as possible. Application hooks can prevent obvious leaks before a model call. The OpenTelemetry Collector can enforce a second layer before traces, logs, and metrics leave your environment. Backend controls help too, but they run after the data has crossed a boundary.

Focus on LLM-specific payload locations:

- Prompt and completion events.
- Tool arguments and tool results.
- MCP request and response bodies.
- HTTP authorization headers and API keys copied into trace attributes.
- Shell output, CI logs, and stack traces returned by tools.
- Transcript logs emitted by agent frameworks.

The [OpenTelemetry Collector redaction processor](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/redactionprocessor) can delete attributes that are not on an allow list and mask attribute values that match blocked patterns. Its README describes traces as beta and logs and metrics as alpha. Use that status when you decide whether it is the right processor for a production path.

A minimal shape looks like this:

```yaml
processors:
  redaction/agent_payloads:
    allow_all_keys: true
    blocked_values:
      - "(?i)bearer\\s+[a-z0-9._-]+"
      - "(?i)api[_-]?key['\"]?\\s*[:=]\\s*['\"]?[a-z0-9._-]+"
      - "AKIA[0-9A-Z]{16}"
    summary: debug

service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [redaction/agent_payloads, batch]
      exporters: [otlp]
    logs:
      receivers: [otlp]
      processors: [redaction/agent_payloads, batch]
      exporters: [otlp]
```

Treat this as a starting pattern, not a complete secret detector. Redaction rules are brittle when they try to recognize every possible secret. Use allow lists for known-safe attributes where you can, delete known-dangerous fields such as authorization headers, and test with canary secrets before export.

For broader Collector patterns, our guide to [redacting sensitive data in OpenTelemetry Collector](https://last9.io/blog/redacting-sensitive-data-in-opentelemetry-collector/) covers processor configuration. The point here is narrower: LLM prompts, completions, tool arguments, tool results, and transcript logs are credential paths. Audit them as such.

## Design observability for opaque provider chains

You often cannot inspect every component behind a model call. A request may pass through your gateway, an inference provider, a reseller, a safety layer, an internal tracing system, and a storage system. You may not control their retention, logging, or support tooling.

Design for that reality:

- Send the minimum payload across the model boundary.
- Record provider, model, route, and policy decision on your side.
- Keep tool payloads inside infrastructure you control when possible.
- Prefer handles over raw values in model-visible content.
- Store a policy version next to each run so you know which capture rules were active.

This lets you answer operational questions without storing dangerous payloads: which provider handled the call, which model ran, whether payload capture was disabled, which tools were called, how long they took, and whether a policy blocked a field.

If you need full payload capture for a severe incident, make it temporary and narrow. Turn it on for one agent, one environment, one time window, and one sampled path. Write the reason in the change record. Turn it off when the incident ends.

## What to do when a secret enters a transcript

If a secret reaches a transcript, act as if it left your control. Redaction is cleanup. It is not containment.

Run this sequence:

1. **Revoke or rotate the credential.** Do this before debating whether the transcript is private.
2. **Identify the first exposure point.** Prompt input, tool result, log line, trace attribute, or provider response.
3. **Search downstream stores.** Check transcript storage, agent logs, traces, logs, exports, eval datasets, SIEM, and cold storage.
4. **Search by fingerprint.** Use a hash or stable prefix where raw search would copy the secret again.
5. **Delete where supported.** Record which systems can delete, which can only expire, and which require vendor support.
6. **Add a regression guard.** A canary secret, input rule, Collector rule, or broker test should fail before the same pattern reaches the model again.

Do not rely on an observability backend to be your incident boundary. By the time telemetry is stored, the credential has already crossed at least one boundary. The revocation step is what makes the old value useless.

## Where Last9 fits in a safer agent telemetry pipeline

Last9 is useful in this pipeline when you want agent behavior in the same place as the rest of your production telemetry. [Agents Monitoring](/docs/agents-monitoring/) is built on OpenTelemetry GenAI semantic conventions, and any instrumentation that emits GenAI-convention telemetry can feed it. The view shows conversations, token consumption, latency, success rate, models in use, and links from a slow or failing LLM span to the full request trace.

For credential control, be precise about the boundary. Last9's [Sensitive Data](/docs/control-plane-sensitive-data/) feature currently supports logs only, and it detects email addresses, phone numbers, and credit card numbers. It is not a general API-key or token detector, and it does not redact trace payloads automatically.

For known fields, use controls that match the signal:

- Use the Collector before export for prompt, completion, tool argument, and tool result attributes.
- Use [Control Plane Drop](/docs/control-plane-drop/) to discard matching logs or traces at ingest when a known pattern should never be stored.
- Use [Control Plane Remapping](/docs/control-plane-remapping/) for logs and traces when you need to standardize or move known fields before search and analysis.
- Use Sensitive Data for the log PII types it documents: email, phone number, and credit card number.

That split matters. It prevents a false sense of safety where "sensitive data scanning" is assumed to catch credentials in every signal. For LLM security, you still need a policy that stops secrets before the model call and before telemetry export.

## LLM security checklist for transcripts and telemetry

Use this checklist when you add observability to a coding agent or agentic workflow:

- **Credentials:** no long-lived credentials in prompts, completions, tool arguments, or tool results.
- **Access:** tools use scoped roles and short-lived credentials; the agent never receives the backing secret.
- **Payloads:** prompt, completion, tool argument, and tool result capture are off by default.
- **Metadata:** run ID, conversation ID, model, provider, tool name, duration, token counts, retries, and error type are on by default.
- **Boundaries:** model, provider, reseller, tool, collector, backend, and export boundaries are mapped.
- **Redaction:** Collector rules delete known-dangerous fields before export.
- **Testing:** canary secrets prove the block and redaction rules work.
- **Retention:** transcript, trace, log, and export retention are documented.
- **Incident response:** revocation, search, deletion, and regression steps are written before the leak.

The test is simple: if a production token appears in the agent UI, will it be blocked before the model call, stripped before telemetry export, or found and revoked quickly? If the answer is unclear, do not turn on payload capture yet.

## FAQ

### How do you keep credentials out of LLM transcripts?

Keep raw credentials away from the model path. Use short-lived tokens, scoped roles, and brokered tool access; block pasted secrets at the agent interface; return resource handles instead of secret values from tools; keep prompt, completion, tool argument, and tool result capture off by default; and redact known fields in the Collector before export.

### Should you store prompts and completions for LLM observability?

Store prompts and completions only when a policy says the debugging value is worth the data risk. Most teams can record metadata by default, including run ID, model, tool name, latency, token counts, error type, and policy decision, then sample or temporarily capture payloads during an investigation. If payload capture is enabled, apply redaction before telemetry leaves your control.

### Can OpenTelemetry redact secrets before export?

Yes. The OpenTelemetry Collector can remove or transform attributes before export, and the contrib redaction processor can delete attributes outside an allow list and mask blocked values. Use it for known fields such as authorization headers and tool payload attributes. Treat it as one control, not a reason to send long-lived secrets into prompts.

### What should you do if a secret appears in an AI transcript?

Revoke or rotate the credential first. Redaction does not undo exposure. Then search transcript stores, logs, traces, and forwarded destinations by exact value where allowed, or by a hash or fingerprint where raw search would spread the secret. Add a regression test or policy rule so the same pattern is blocked before the next agent call.
