Policy Compliance Audit Log Analysis and Incident Reporting Script Builder
Generate an automated SQL and Python reporting script to aggregate audit logs, detect access violations, and report policy anomalies.
Use this template when building regulatory audit pipelines across access control or permission tables. It creates automated incident reporting scripts suitable for legal and governance reviews.
Role: Principal Compliance Data Analyst specializing in governance reporting automation.
Context
- Database engine: {{audit_log_database_engine}}
- Compliance standard: {{compliance_framework_standard}}
- Target role scope: {{monitored_user_roles}}
- Audit lookback window: {{violation_lookback_window}}
- Severity taxonomy: {{incident_severity_classification}}
- Alert endpoint: {{notification_webhook_target}}
Task
Develop an automated SQL extraction query and Python wrapper script that scans security event logs, identifies unauthorized permission escalations and policy breaches according to compliance requirements, categorizes incidents by risk tier, and produces a structured summary report sent to an incident webhook.
Method
- Formulate a parameterized SQL extraction query tailored for {{audit_log_database_engine}}.
- Filter access logs across the designated {{violation_lookback_window}} specifically isolating {{monitored_user_roles}}.
- Implement parsing logic against policy evaluation rules defined by {{compliance_framework_standard}}.
- Map raw violation patterns against {{incident_severity_classification}} to establish risk scores.
- Aggregate incident totals by role category, resource path, and root-cause event code.
- Compile high-severity findings into a concise markdown-formatted digest payload.
- Dispatch the payload via HTTP POST to {{notification_webhook_target}} with retry logic.
Constraints
- Queries MUST use parameterized inputs to prevent SQL injection.
- MUST NOT expose raw passwords, user secrets, or personal identifiable information (PII) in output payloads.
- Script MUST exit cleanly with code 0 on zero violations and code 1 on unhandled database errors.
- Log volume estimation must include index utilization recommendations for performance optimization.
Output format
Provide the response structured as follows:
- SQL Audit Extraction Query (clean, optimized SQL block with parameter placeholders).
- Python Dispatcher Script (production-ready Python script handling extraction, classification, and webhook dispatch).
- Payload Schema (JSON sample of the summary incident digest).
Self-review
- Verify that the SQL query matches syntax rules for {{audit_log_database_engine}}.
- Confirm that severity classification logic covers all edge cases specified in {{incident_severity_classification}}.
- Ensure webhook timeout and retry mechanics are explicitly declared in the Python script.
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.