How to log an AI agent without logging secrets
Tracing an AI agent is essential for understanding its decisions, but copying every prompt and response into logs creates a new risk. This framework combines NIST, OWASP and OpenTelemetry guidance into a proportionate trace policy.
Short answer
An AI agent must be observable, but its log should not become a copy of business data. The practical balance is to trace the events needed for operations and security, classify content before retention, redact secrets and set a documented retention period. OpenTelemetry describes conventions for model and tool operations; OWASP warns that insufficient or poorly protected logs prevent detection and can expose sensitive data. The framework below separates technical traces, business content and compliance evidence.
The wrong instinct: keep everything so everything can be explained
When an agent is hard to diagnose, teams often enable debug mode and record the full prompt, full response, tool results and retrieved documents. This gives immediate visibility, but it mixes three different uses: troubleshooting an incident, measuring quality and proving that a policy was followed. Each use has a different lifetime, access level and detail requirement.
The risk is documented by several primary sources. OWASP's A09:2025 page on security logging and alerting failures explicitly includes sensitive data in log files, inadequate encoding and missing integrity controls. NIST AI 600-1 asks organizations to govern, measure and manage generative AI risks throughout the lifecycle. These sources do not prescribe one log format for every agent. They establish a method: know what is observed, why, by whom and for how long.
Nexxom diagram: events are captured, classified, redacted or retained according to sensitivity and purpose. It is a design model, not a mandatory implementation.
What to trace to understand an agent
OpenTelemetry defines semantic conventions for representing events and operations. Its GenAI observability guide describes attributes for the model called, tokens, prompts, completions and tools, while full content capture remains an explicit choice. A convention helps teams use stable signal names. It does not decide which content your organization may retain.
A useful trace should answer five questions:
- Which system acted? Model version, orchestrator version, environment and technical identity.
- Which objective was pursued? Task identifier, workflow type and applied policy, without automatically copying the user's request.
- Which transitions occurred? Model call, tool call, result, error, retry, stop or human approval.
- Which risk was detected? PII, secret, contractual data, external action or untrusted content.
- Which decision was made? Allow, redact, block, escalate or schedule deletion.
| Signal | Main use | Content to limit |
|---|---|---|
| Trace identifier | Connect a task and its sub-operations | Do not use a stable user identifier without a need |
| Version and parameters | Reproduce a regression | Do not record keys or access headers |
| Tool call | Understand an external action | Hash or filter sensitive arguments |
| Status and latency | Diagnose availability and cost | Keep business content out of metrics |
| Control decision | Prove a block or approval | Retain the applied rule, not the full document |
| Content fingerprint | Link two steps without exposing text | Use a hash with an appropriate salt policy |
This list can diagnose many incidents without retaining the raw conversation. If a team needs to inspect a passage to correct a model, it can open a temporary controlled copy and delete it under a stated policy. The production trace keeps the copy identifier, access reason and review outcome.
Three detail levels, three retention policies
Separating levels prevents every log from being treated as if it had the same value. The operational level contains metadata needed for alerts and support. The diagnostic level adds minimized, often pseudonymized excerpts for an incident. The evidence level keeps policy decisions, versions and fingerprints needed for an audit.
| Level | Example content | Access | Retention direction to define |
|---|---|---|---|
| Operational | duration, status, model, tool, token count | operations team | short period aligned with monitoring |
| Diagnostic | redacted excerpt, structured error, recovery steps | restricted team | incident resolution period |
| Evidence | rule, decision, timestamp, version, hash | security, compliance | legal or contractual need |
The periods in this table are not legal obligations. They illustrate a decision that must be documented. The exact period depends on sector, legal basis, contracts, location and security policy. A trace containing personal data does not become neutral because it sits in an observability platform.
Classify before you redact
Redaction should happen before export to the log platform whenever possible. A downstream filter may hide data from a dashboard without removing it from temporary copies, queues or backups. The pipeline should therefore identify authentication secrets, personal contact data, health or financial information, contract documents and confidential instructions at minimum.
Classification is not perfect. A detector may miss a contract number or replace a technical term by mistake. For high-impact flows, combine automatic detection, business rules, human sampling and a stop mechanism. Keep the classifier version and treatment decision so a team can explain why a field was retained, masked or blocked.
Make the classification decision visible in the trace without exposing the value that triggered it. For example, record sensitivity=personal_data and treatment=redacted, but do not write the email address that was detected. A reviewer can then assess whether the rule fired and whether the downstream action was allowed. If a false positive blocks a useful workflow, the reviewer can change the rule or grant an explicit exception instead of opening every raw prompt.
The same separation applies to vendors. An observability provider may receive spans, logs or metrics through a different retention and access model than the application that produced them. Document which fields leave the execution environment, which are encrypted, which support staff can access them and how deletion propagates to exports and backups. This inventory is part of the trace policy, not an optional procurement detail.
Nexxom matrix: sensitivity and purpose determine the detail level. The zones are design guidance, not universal legal periods.
A minimal event schema
An event can be represented with a stable name, timestamp, trace identifier, version and control result. Content fields are optional and should follow a classification decision. The example below is conceptual; it does not replace your observability vendor's conventions.
{
"event": "tool.call.completed",
"trace_id": "random-per-request",
"workflow": "support-ticket",
"model": "provider/model-version",
"tool": "ticket.search",
"status": "success",
"policy": "support-v3",
"sensitivity": "redacted",
"content_hash": "sha256:...",
"human_review": false
}
This format makes transitions and outcomes queryable without publishing the full request. For errors, use controlled categories such as timeout, policy_block, tool_error or schema_error. Do not put the prompt or answer into an error field that is automatically copied into an alert or ticket.
Detect attacks in logs without creating a new leak
Logs also support security. Unusual call sequences, repeated control failures or an attempt to access an out-of-scope tool can trigger an alert. OWASP A09:2025 recommends protecting log integrity, preventing injection into the logging system, backing up logs and defining alert thresholds that lead to a real response.
An alert should therefore be designed as an action, not a counter. Define who receives the event, the response time, the minimum evidence and how the agent is isolated. A dashboard that shows a sensitive prompt to too many people increases risk without speeding up response. Prefer a summarized alert linked to a restricted trace and an exceptional-access procedure.
Verify the design before production
- Map outputs. List application logs, distributed traces, metrics, alerts, tickets and backups.
- Classify fields. Mark secrets, personal data, business content, technical identifiers and public data.
- Define the minimum. For every field, write the operational question it answers.
- Test leakage. Inject non-sensitive canary values and verify they do not reach unauthorized exports.
- Test controls. Simulate a forbidden tool call, empty response, retry and delayed alert.
- Check access. Review roles, exports, backups, keys and deletion.
- Replay an incident. Confirm an authorized person can understand the cause without opening every conversation.
Test results should distinguish a content leak, a missing trace, a missed alert and evidence that cannot be linked. The objective is not to collect as much data as possible. It is to make a decision verifiable with the least sensitive data necessary.
What this changes for teams
For some teams, structured metadata and fingerprints are enough to operate a low-impact agent. For others, a regulated process needs temporary access to a redacted excerpt, an approval and longer retention of control evidence. In both cases, the choice should be explicit, tested and revisited when the model, tool or data scope changes.
The practical recommendation is to start with a logging contract: allowed events, forbidden fields, access levels, retention, alerts and an owner. OpenTelemetry can help normalize signals. NIST and OWASP can connect those signals to a risk program. None of these references decides what your organization is allowed to retain.
Sources checked on 5 October 2026
- OpenTelemetry, semantic conventions for events, official documentation consulted on 5 October 2026.
- OpenTelemetry, GenAI observability, official article dated 14 May 2026.
- OWASP A09:2025, Security Logging & Alerting Failures, 2025 edition consulted on 5 October 2026.
- NIST AI RMF Generative AI Profile, NIST AI 600-1.
- Kahani et al., Runtime Compliance Verification for AI Agents, arXiv, 17 June 2026.

