Skip to content

Audit Logger Middleware #9

Description

@veeqtoh

Is your middleware request related to a problem? Please describe.

Production AI-native applications need immutable audit trails for compliance, debugging, and security forensics. The existing callback mechanism in Intercept allows ad-hoc logging, but there is no standardized, append-only audit layer across all middleware actions.

Proposed solution

Implement an AuditLogger middleware that is a pass-through (does not modify the prompt) and writes structured audit records for every intercepted prompt/response cycle.

API Design

// In an agent's middleware stack
public function middleware(): array
{
    return [
        new PromptInjectionGuard,
        new PIIRedaction,
        new AuditLogger(storage: 'database'), // or 'file'.
    ];
}

Configuration

'audit' => [
    'driver' => env('INTERCEPT_AUDIT_DRIVER', 'database'), // database|file
    'table' => 'intercept_audits',
    'connection' => null,
    'prune_days' => 90,
],

Schema

Column Type Description
id bigint PK
agent string Agent class name
middleware json Which middleware ran
prompt_hash string xxh3 of prompt payload
response_hash string xxh3 of response payload
action_taken string blocked|redacted|allowed
user_id nullable Authenticated user
ip_address string Request IP
duration_ms int Round-trip time
created_at timestamp

Describe the middleware's supported actions you'd like**

N/A

Additional context

This need is highlighted in production guides for Laravel AI SDK middleware, which recommend audit trails as a core production requirement alongside input validation.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions