New Tool Radar

AI Agents & Automation

How to Keep Agent Secrets Out of Logs and Prompts

Keep agent secrets out of logs and prompts so keys never appear in stored text.

Schematic with three steps: List every secret and where it could; Pass secrets by reference, never by value; Search the stored trace and log for.

A secret that reaches a log or a prompt is a secret that is stored: API keys, tokens, and passwords end up in traces, in history, and in anything the run saves. Once stored, they are readable by anyone with access to those stores, and they stay there until someone finds and removes them. The fix is to never let secrets into those places at all: pass them by reference, such as an environment variable name or a vault reference, and keep the value out of the text the model sees and the log writes. LangSmith traces record what agents did in production, which makes them a place where a leaked secret does real damage. Check the stored text, not the intention.

What you need

  • A list of the secrets the agent uses: API keys, tokens, passwords
  • A way to pass secrets by reference, such as environment variables
  • A sample trace and log to check for leaked secrets

Step 1: List every secret and where it could leak

Write down each secret and every place it could appear: prompts, tool arguments, error messages, logs, and traces. A secret with no listed leak path is a secret you have not thought about.

Step 2: Pass secrets by reference, never by value

Give the agent the name of the secret, such as an environment variable, and let the tool read the value itself. A secret pasted into a prompt is a secret in the stored history.

Step 3: Search the stored trace and log for the secret

After a test run, search the stored trace and log for each secret value and confirm none appears. If one does, find the step that wrote it and fix that step, not just the stored copy.

Worked example: synthetic secret handling check

The table below is a synthetic example. It shows the expected result of keeping secrets out; no secret was stored.

Secret In prompt? In stored log?
API key No – by reference No
OAuth token No – by reference No
Database password No – by reference No
No secret in stored text Yes Pass

Expected result (UNTESTED). every secret is passed by reference, and no secret value appears in any prompt, trace, or stored log. This check was not run live; the table shows the expected result for the synthetic example.

Limits

  • A secret in an error message is still a leak; check errors as well as prompts.
  • Passing by reference only helps if the tool reads the reference; a tool that logs its arguments leaks anyway.
  • A secret already stored must be rotated, not just deleted from the log.
  • Test data can leak too: use fake secrets in tests, never real ones.

Sources

See all