Bonaventure OgetoBy Bonaventure Ogeto|

Audit Trails for AI-Initiated Financial Actions

For every AI-initiated financial action, log: 1) Agent session ID and model version. 2) The user instruction or system event that triggered the action. 3) Tool name called (e.g., "paystack_transfer"). 4) Parameters passed (recipient, amount, reason). 5) Paystack API response (transfer_code, status). 6) Timestamp. 7) Whether human review occurred and who approved. Store logs in append-only storage — never let the agent modify or delete its own logs.

Audit Log Schema for AI Financial Actions

// Append-only audit log for every AI-initiated financial action
async function logAgentAction({ sessionId, modelVersion, trigger, toolName, params, response, humanApproved = null }) {
  // Write BEFORE executing the action — so even failures are logged
  var logEntry = {
    id: crypto.randomUUID(),
    ts: new Date().toISOString(),
    session_id: sessionId,
    model_version: modelVersion,     // e.g. "claude-opus-4-6"
    trigger,                          // the instruction or event that caused this action
    tool_name: toolName,              // e.g. "paystack_transfer"
    params: JSON.stringify(params),   // recipient, amount, reason — serialized
    response: null,                   // filled after execution
    human_approved: humanApproved,    // { by: "bonaventure@mctaba.com", ts: "..." } or null
    status: 'pending',
  };

  var entry = await db.aiAuditLog.insert(logEntry);

  return {
    logId: entry.id,
    // Call this after execution to record the outcome
    recordOutcome: async (apiResponse, status) => {
      await db.aiAuditLog.update(entry.id, {
        response: JSON.stringify(apiResponse),
        status, // 'success' | 'failed' | 'blocked'
      });
    },
  };
}

// Usage: log before transfer, record outcome after
async function agentTransfer({ sessionId, modelVersion, trigger, recipientCode, amount }) {
  var audit = await logAgentAction({
    sessionId, modelVersion, trigger,
    toolName: 'paystack_transfer',
    params: { recipientCode, amount },
  });

  try {
    var res = await fetch('https://api.paystack.co/transfer', {
      method: 'POST',
      headers: { Authorization: 'Bearer ' + process.env.PAYSTACK_SECRET_KEY },
      body: JSON.stringify({ source: 'balance', amount, recipient: recipientCode, reference: 'agent_' + audit.logId }),
    });
    var data = await res.json();
    await audit.recordOutcome(data, data.status ? 'success' : 'failed');
    return data;
  } catch (err) {
    await audit.recordOutcome({ error: err.message }, 'failed');
    throw err;
  }
}

Making AI Audit Logs Immutable

  • Supabase RLS — enable Row Level Security on the audit log table. Grant INSERT to the agent service role, deny UPDATE and DELETE to everyone including service_role. Verified by RLS policies, not application code.
  • Append-only DB columns — use PostgreSQL triggers that raise exceptions on UPDATE/DELETE of the audit table:
CREATE OR REPLACE FUNCTION prevent_audit_modification()
RETURNS TRIGGER AS $$
BEGIN
  RAISE EXCEPTION 'AI audit log entries cannot be modified or deleted';
END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER no_audit_update BEFORE UPDATE ON ai_audit_log FOR EACH ROW EXECUTE FUNCTION prevent_audit_modification();
CREATE TRIGGER no_audit_delete BEFORE DELETE ON ai_audit_log FOR EACH ROW EXECUTE FUNCTION prevent_audit_modification();
  • Cloud storage — for long-term retention, export daily audit logs to S3 or GCS with Object Lock (WORM) enabled. Once written, the log file cannot be overwritten for the retention period.
  • Hash chaining — each log entry stores the SHA-256 hash of the previous entry. Tampering with any entry breaks the chain and is detectable.

Learn More

See agentic payout safety rails for what to prevent before an action reaches the audit log.

Sign up for the McTaba newsletter

Key Takeaways

  • Log agent session ID, model version, triggering instruction, tool calls, parameters, and API response for every financial action.
  • Audit logs for AI actions must be append-only — the agent must not be able to modify or delete them.
  • Include a human_reviewed field: who approved the action and when (null if automated below threshold).
  • Log BEFORE executing the action so failed actions are still traceable.
  • Retain AI financial audit logs for at least 7 years — the same requirement as other financial records.

Frequently Asked Questions

Does Paystack keep its own audit log of API calls?
Paystack records which API key was used for each action, and you can see transfer and transaction history in the dashboard. But Paystack has no record of what AI agent, session, or instruction triggered the call. That context lives only in your own audit log. If you need to explain to a regulator or auditor why a specific transfer was made, Paystack's logs alone are not enough — you need the AI session context.
How do I prove in an audit that the AI, not a human, made a transfer?
Your audit log entry must include: session_id (unique per agent conversation), model_version (which AI model was used), trigger (the instruction that caused the action), and human_approved (null for automated actions, or the approver's identity for human-reviewed ones). The transfer reference in Paystack should include the audit log ID — e.g., "agent_<uuid>" — so you can cross-reference Paystack records with your audit log.
How long should I keep AI financial audit logs?
Apply the same retention period as your other financial records. In Nigeria, FIRS requires 6 years of financial records. In Kenya, KRA requires 5 years. In practice, keep AI financial audit logs for 7 years to cover the maximum common requirement. AI actions that involved transfers, refunds, or subscription changes should be treated with the same seriousness as journal entries.

Ready to build real-world apps?

Join the McTaba Labs full-stack marathon (4 months full-time · 6 months part-time). Learn M-Pesa, USSD, and WhatsApp engineering while shipping 8 production apps.

Apply to the McTaba Marathon