Back to blog
Security · Audit

Best Way to Log and Audit What an AI Agent Did in Your Database: n8n, Slack and SIEM

Record the request, the verdict and whether your code ran the write. n8n can alert Slack and forward a redacted event to the SIEM.

Claix · November 2026. Related guides: what to record for auditors, Slack approvals, and n8n. Product: Claix Retrieve and Claix Guard.

A conversation transcript tells you what the agent said. It may not tell you which data it touched, which route applied, or whether a write was allowed, denied or executed. The test is simple: when the agent produces an unexpected result, can you reconstruct what happened without trusting its explanation?

Why AI agents need audit logs

An agent can receive an instruction, choose a tool, generate a query and act in seconds. Without a trail you cannot answer who asked, which tenant was in scope, whether the query stayed on its route, whether a write was proposed, what the verdict was, whether the write ran, which rule denied it, or how the events connect.

The three events you need to distinguish

EventWhat it tells you
Agent requestWhat the agent tried to do
Control decisionWhether the request was allowed, denied or failed validation
Execution resultWhether the action actually completed

Those outcomes diverge. A check can allow a statement that then fails in your database node. An agent can be denied and try a different statement. A timeout can leave the caller unsure whether the write finished. Logging only the final sentence hides that.

What to record

Record enough to reconstruct the event. Do not record credentials or full result sets by default.

FieldWhy it matters
TimestampWhen the event happened
Request ID and correlation IDLinks the agent, the check and the executor
Tenant and userWho the request was for
Agent and routeWhich boundary was used
User inputWhat was asked, after you redact secrets
Validation resultWhether the query stayed on the route
Write proposal and Guard decisionWhat was proposed, the verdict and the reason
Execution status, duration and errorWhether your code finished the action

What Claix records

Retrieve validates a query before it runs and traces the request: what was asked, which route answered and what came back. Each call also returns log_id, which is the id to open in Traces. Guard records the proposed statement, the verdict code and the reason. On a denial, violations name the rules that blocked it. A denial is still HTTP 200. Read allowed. needs_approval also has allowed set to false, and it is a different code from a hard denial.

Claix does not record whether your executor later committed the write or called a payment gateway. That row belongs in your log.

How to send alerts to Slack

VerdictSlack behaviorEndpoint behavior
AllowedPlain messageCheck result, including SQL
DeniedPlain messageCheck result, including SQL
Needs approvalMessage with Approve and Reject buttonsCheck result, including SQL

Only needs_approval messages include buttons. When someone clicks, Claix signs a POST to the endpoint you configured. The header X-Claix-Signature is an HMAC-SHA256 of the body. A body without the optional SQL looks like this:

{
  "approval_id": "7d8e9f0a-1b2c-4d3e-8f90-a1b2c3d4e5f6",
  "decision": "approved",
  "statement_hash": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
  "timestamp": "1763726400",
  "approver": "U0123456789"
}

The SQL is included in that POST only if you turn the option on. Verify the signature, then log the decision. Setup: connect Slack.

How to send alerts to a SIEM

Claix does not push events into a SIEM product. It can send each verdict to a public HTTPS endpoint you already run. That endpoint, often an n8n webhook, forwards a structured event onward. Include the timestamp, event type, agent, tenant, user, route, validation result, write proposal, Guard decision, denial reason, execution status, duration and a correlation id. Redact parameters that are secrets. Decide who can read the log.

How to use n8n for alerting

  • A Webhook trigger receives the Claix event.
  • A filter separates allowed, denied and needs_approval.
  • A Slack node sends the alert to a private channel. The payload can include SQL.
  • A second node forwards the redacted event to the SIEM.
  • An error path records a failed forward so the audit gap is visible.

How to structure the trail

LayerWhat it records
Agent layerUser input, agent identity, task and model response
Retrieval layerRoute, tables, columns, validation result and returned scope
Guard layerProposed write, verdict and reason
Executor layerExecution status, duration and error details
Database layerDatabase activity and constraints
Access layerWho inspected the logs, and when

Retrieve and Guard cover the retrieval and decision rows. Your systems cover execution and who later opened the logs.

How to investigate an incident

  • Start from the request id, the correlation id or the Retrieve log_id.
  • Identify the agent and the tenant.
  • Read the user input and the agent’s response.
  • Read the route and the data scope.
  • Read the validation result and any tool call that sent data elsewhere.
  • Read the write proposal, the Guard verdict and the reason.
  • Read the execution status in your own log.
  • Check whether the same pattern shows up on other requests, then change the boundary.

The point is to see which control failed. Afterward, narrow a route, drop a column, add a Guard rule, add a human-review step, or keep a field you were missing. One concrete change is enough to start.

How to get started

Claix supports Postgres, MySQL, MariaDB and Supabase. Connect with a read-only role. Call Retrieve for reads and Guard before writes. Point allowed, denied and needs_approval at the n8n webhook that alerts Slack and forwards to the SIEM. Keep write credentials in that executor.

Conclusion

An audit log is the difference between believing the agent and showing the request, the rule and the outcome. Retrieve traces the read. Guard records the verdict. Your webhook records whether the statement ran, and it can tell Slack and the SIEM. Design that trail before the first incident.