2026-01-20 · Authensor

How to Log Every AI Agent Action for Compliance

Compliance frameworks including SOC 2, HIPAA, GDPR, PCI-DSS, and ISO 27001 require complete, accurate, and tamper-proof records of system actions — AI agents are no exception. SafeClaw by Authensor logs every action an AI agent attempts, whether allowed or denied, in a structured format with hash-chained integrity. Every log entry includes the action type, the policy decision, the matched rule, and full request details, giving you the audit evidence compliance requires without any additional logging infrastructure.

Quick Start

npx @authensor/safeclaw

Scaffolds a .safeclaw/ directory with comprehensive logging enabled by default.

Step 1: Map Compliance Requirements to Log Fields

Different frameworks require different information. Configure SafeClaw to capture all fields you need:

# .safeclaw/config.yaml
audit:
  enabled: true
  hashChain: true
  format: "jsonl"
  fields:
    # Core fields (all frameworks)
    - timestamp          # When the action was attempted
    - action             # What action was attempted (file.write, shell.execute, etc.)
    - effect             # Allow or deny decision
    - matchedRule        # Which policy rule made the decision
    - reason             # Human-readable reason for the decision

# Identity fields (SOC 2, ISO 27001)
- agentId # Which AI agent
- sessionId # Which session
- userId # Which human initiated the agent

# Detail fields (HIPAA, PCI-DSS)
- requestDetails # Full action details (file path, command, API endpoint, etc.)
- evaluationDurationMs # How long policy evaluation took

# Integrity fields (all frameworks)
- hash # Entry hash
- prevHash # Previous entry hash (chain link)
- sequence # Monotonic sequence number

Step 2: Configure Retention by Framework

Different compliance frameworks have different retention requirements:

audit:
  retention:
    default: "3y"     # SOC 2 minimum
    overrides:
      hipaa: "6y"     # HIPAA requires 6 years
      financial: "7y"  # SOX/PCI-DSS requires 7 years
      gdpr: "matched"  # GDPR: retain only as long as necessary
  rotation:
    maxSize: "500MB"
    compress: true
    archiveTo: "s3://audit-archive/"

Step 3: Structured Log Output

Every action produces a structured JSON log entry:

{
  "sequence": 4821,
  "timestamp": "2026-02-13T10:45:23.102Z",
  "action": "database.query",
  "effect": "deny",
  "matchedRule": "block-pii-fields",
  "reason": "Agent must never query PII-sensitive columns",
  "agentId": "customer-service-agent-03",
  "sessionId": "sess_xyz789",
  "userId": "support-lead@company.com",
  "requestDetails": {
    "query": "SELECT name, email, ssn FROM customers WHERE id = 42",
    "database": "production"
  },
  "evaluationDurationMs": 0.18,
  "hash": "sha256:a1b2c3d4...",
  "prevHash": "sha256:e5f6g7h8..."
}

This single entry satisfies multiple compliance requirements simultaneously:


Step 4: Log Both Allows and Denials

SafeClaw logs every action attempt, not just denials. This is critical for compliance — you need to prove what was accessed, not just what was blocked:

{
  "sequence": 4822,
  "timestamp": "2026-02-13T10:45:24.305Z",
  "action": "database.query",
  "effect": "allow",
  "matchedRule": "allow-read-ticket-info",
  "reason": "Agent can read ticket metadata",
  "agentId": "customer-service-agent-03",
  "sessionId": "sess_xyz789",
  "requestDetails": {
    "query": "SELECT id, subject, status FROM tickets WHERE customer_id = 42"
  },
  "hash": "sha256:b2c3d4e5...",
  "prevHash": "sha256:a1b2c3d4..."
}

Step 5: Route Logs to Compliance Systems

Send structured logs to your compliance and SIEM tools:

audit:
  destinations:
    - type: file
      path: "logs/audit.jsonl"

- type: syslog
host: "siem.internal.company.com"
port: 514
format: "cef" # Common Event Format for SIEM

- type: webhook
url: "${COMPLIANCE_WEBHOOK}"
batchSize: 100
flushInterval: "5s"

- type: s3
bucket: "compliance-audit-logs"
prefix: "safeclaw/{{year}}/{{month}}/"
objectLock: true
retentionMode: "COMPLIANCE"
retentionDays: 2555 # 7 years

Step 6: Generate Compliance Reports

Extract compliance-specific reports from your audit trail:

# SOC 2 access control report
npx @authensor/safeclaw audit report \
  --framework soc2 \
  --period "2026-Q1" \
  --output soc2-q1-report.pdf

HIPAA access audit

npx @authensor/safeclaw audit report \ --framework hipaa \ --period "2026-02" \ --include-phi-access \ --output hipaa-feb-audit.pdf

ISO 27001 evidence package

npx @authensor/safeclaw audit report \ --framework iso27001 \ --period "2026-01-01:2026-02-13" \ --include-chain-verification \ --output iso27001-evidence.zip

Why SafeClaw

Cross-References

Try SafeClaw

Action-level gating for AI agents. Set it up in your browser in 60 seconds.

$ npx @authensor/safeclaw