Safeguard
Security Guides•

What should you keep out of AI agent logs?

Keep tokens, secrets, session IDs and sensitive personal data out of AI agent logs, or mask them. Here is a checklist for prompts, tool calls and outputs.

Safeguard Security Team
4 min read

Keep access tokens, passwords, keys, connection strings, session identifiers and sensitive personal data out of AI agent logs, or mask, hash or encrypt them before writing. Log who, what, when and the outcome of each action, not the secret the agent used to do it.

Why agent logs are riskier than most

An agent's prompts, tool arguments and tool results often contain whatever the agent was working on. That can include customer records, source code, and credentials pasted into a conversation. Write all of it to a log and you have created a second copy of your most sensitive data, usually with weaker access control than the original.

OWASP's logging guidance lists what should usually not be recorded directly and should instead be removed, masked, sanitized, hashed or encrypted: application source code, session identification values, access tokens, sensitive personal data, authentication passwords, database connection strings, encryption keys and other primary secrets, and payment data. Every item on that list can appear in an agent's input or output.

A practical keep and drop table

ItemLog it?How
Agent identityYesAs is
Tool name and action typeYesAs is
Target resource IDYesAs is, if not itself sensitive
Timestamp and outcomeYesAs is
Approval decision and approverYesAs is
Access tokens and keysNoNever store; log a token ID or hash if needed
Full prompt textCarefulShort retention, redact secrets
Tool arguments with personal dataCarefulMask fields, log field names
Full file contents read by the agentNoLog path and size instead
Session IDsCarefulHash if you need to correlate

Steps to set it up

  1. Define a log schema for tool calls with fixed fields, so engineers do not dump raw objects.
  2. Add a redaction step before the logger, with patterns for tokens, keys and common personal data fields.
  3. Replace secrets with references. A log line that says credential id 4821 was used is far safer than one that shows the credential.
  4. Log content at a separate, shorter retention tier if you need it for debugging, with tighter access.
  5. Test with fake secrets. Send a dummy token through the agent and grep the logs for it.
  6. Review access to logs periodically. OWASP advises restricting read privileges and reviewing them.

Watch for log injection

Agents read untrusted text, and untrusted text can end up in your logs. OWASP points to log injection and CWE-117 as attacks on logs. Treat anything the model or a tool returns as untrusted data: encode it, and never let it forge a new log line.

The conflict with debugging

Developers want full traces. Security wants less. A workable compromise is a debug mode that is off by default, switches on per agent for a limited time, writes to a restricted store, and expires. Make the switch itself a logged event.

What about the legal side

Some data should not be collected at all. OWASP notes that logging certain communications, monitoring employees, or collecting data without consent can be illegal. Ask your privacy team before you start capturing full conversations with people.

Safeguard's policies and guardrails help control what agents can reach, which reduces what ends up in their logs, and a free scan is available at https://gold.safeguard.sh/scan.

Quick check

Is it fine to log the full prompt for debugging?

Only with redaction, a short retention period and restricted access. Prefer logging metadata by default.

How do I prove a secret is not in my logs?

Pass a fake token through the agent in a test and search the logs for it. Repeat after each logging change.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.