4 min read

How to Keep a Readable Audit Log of AI Agent Tool Calls with JSON

A practical way to record what an AI agent did: a simple JSON log schema, how to validate and diff entries, and when to move from files to a tracing platform.

UrwaTools Editorial Published
Contents

When an AI agent sends an email, updates a record or calls a search API, someone eventually asks the same question: what exactly did it do, and why? Teams that cannot answer in a few minutes lose time, and teams that must keep records for customers or regulators lose more. The good news is that a useful audit trail does not need a platform on day one. A disciplined JSON log gets you surprisingly far.

What an agent log entry should contain

Treat every tool call as one JSON object. Keep the shape small and the same every time, so entries can be compared and searched later. A practical minimum looks like this:

  • run_id and step: which agent run this belongs to and the order of the call.
  • timestamp: in UTC, ISO 8601 format, so logs from different machines line up.
  • tool: the tool name, such as a search call or a calendar update.
  • input and output: the arguments sent and the result returned, trimmed if they hold personal data.
  • model and version: which model and which prompt version produced the decision.
  • approved_by: empty for fully automatic steps, or the person who approved a human-in-the-loop step.

Write one entry per line (often called JSON Lines) so you can append safely and never rewrite old records.

Raw agent output is often a single long line. Paste a sample entry into the JSON Formatter to see the structure, and use the JSON Minifier when you need to put an entry back on one line for storage. Models sometimes return almost-valid JSON, with a trailing comma or single quotes. The JSON Repair Tool helps you fix those examples by hand so you can see what went wrong before you change your parser.

A log is only useful if every entry has the same fields. Start from a real entry and use the JSON Schema Generator to draft a schema, then tighten it by hand: mark the required fields, set the timestamp format, and list the allowed tool names. Check sample entries against it with the JSON Schema Validator. In production, run the same validation in code before a record is written, and reject or flag entries that do not match.

The fastest way to understand a surprising run is to compare it with a good one. Export both logs and compare matching steps in the JSON Diff tool. Differences in the tool inputs usually explain a different outcome. If a prompt version changed between the two runs, that is often the cause. When entries are deeply nested, the JSON Flattener turns them into simple key and value pairs that are easier to scan.

Managers, support teams and reviewers rarely want raw JSON. Convert a batch of entries with JSON to CSV and open the result in a spreadsheet. Sort by step, filter by tool, and mark anything that needed a human approval. The same low-tech pattern works for model experiments, as described in this guide to tracking ML experiments with JSON and CSV.

  • Trim personal data. Log identifiers rather than full names or message bodies when you can.
  • Decide how long to keep records. Some rules for automated decisions ask for multi-year retention, so check the requirements that apply to you with a qualified adviser. This article is general information, not legal advice.
  • Restrict access. Logs often contain more than people expect. Limit who can read them.
  • Never log secrets. API keys and tokens must be removed before an entry is written.

A file-based log is a good start, but there are clear signs you have outgrown it: several people need to search it at once, you need to replay a run step by step, or you need automatic evaluation of outputs. At that point a tracing and evaluation platform is worth the cost. Many agent frameworks include or integrate with one. ProductListo's directory lists frameworks such as LangChain and LlamaIndex, and its AI and ML buyer guide covers the wider category. For a view of how the framework market changed this year, including notes for teams in the US and South Korea, see ProductListo's explainer on AI agent frameworks in 2026.

For a broader introduction to where agents work well and where they do not, read UrwaTools' overview of AI agents in 2026.

Makers of agent tools can submit a tool to the ProductListo directory or ask about sponsored placements and guest articles on its write for us page.

  1. Pick one JSON shape and write it down.
  2. Log every tool call, including failures.
  3. Validate each entry against a schema before saving it.
  4. Store UTC timestamps and prompt versions.
  5. Review a sample of runs every week, comparing good and bad ones.
  6. Set a retention period and remove secrets and unneeded personal data.

Frequently asked questions

What should an AI agent audit log include?
At minimum: a run identifier, step number, UTC timestamp, tool name, the input and output of the call, the model and prompt version, and who approved the step if a human was involved.
Why use JSON Lines for agent logs?
One JSON object per line lets you append new entries without rewriting the file, and most tools can read it line by line, which keeps large logs manageable.
How do I check that every log entry has the same fields?
Write a JSON schema that lists the required fields and their formats, then validate each entry against it, first with an online validator while prototyping and then in code before saving.
When do I need a tracing platform instead of files?
When several people must search logs together, when you need to replay runs step by step, or when you want automatic evaluation of outputs. Until then, a validated JSON log is often enough.
Should I log personal data from agent runs?
Keep it to a minimum. Log identifiers instead of full names or message text when possible, remove secrets, limit access and check retention rules that apply to you with a qualified adviser.
Written by UrwaTools Editorial

The UrwaTools Editorial Team delivers clear, practical, and trustworthy content designed to help users solve problems efficiently. Our articles focus on accurac...