congiuluc/my-awesome-copilot/audit-backend-python
Claude Code and agent skill by congiuluc/my-awesome-copilot
Trust tier 3
- community
Source check pending
Checking that the SKILL.md file is still in the repository.
Implement audit logging and audit trails for Python FastAPI applications. Covers SQLAlchemy event listeners, middleware-based action logging, Pydantic audit models, and compliance patterns. Use when: adding audit trails to data changes, logging user actions, implementing compliance requirements (GDPR, SOC2, HIPAA), or reviewing audit coverage in Python.
Install
npx vskill@latest install congiuluc/my-awesome-copilot/audit-backend-pythonSKILL.md
The same SKILL.md was published earlier as congiuluc/my-awesome-copilot/audit-backend-python.
Audit Logging (Python FastAPI)
When to Use
- Adding audit trails for entity create/update/delete operations
- Logging user actions (login, permission changes, data access)
- Implementing compliance audit requirements (GDPR, SOC2, HIPAA)
- Reviewing existing audit coverage for gaps
- Adding tamper-proof audit storage
Official Documentation
Key Principles
- Audit is separate from logging — audit events are business-critical records, not debug logs.
- Immutable and append-only — audit records must never be updated or deleted.
- Who, What, When, Where — every audit entry captures the actor, action, timestamp, and target.
- Sensitive data handling — store what changed but redact PII where required.
- Async and non-blocking — audit writes must not slow down the primary operation.
Procedure
- Define the
AuditEntryPydantic/SQLAlchemy model (see audit model sample) - Implement SQLAlchemy
after_insert,after_update,after_deleteevent listeners - Add a FastAPI middleware for HTTP request-level action auditing
- Store audit records in a dedicated, append-only table
- Include the actor (user ID), action type, entity type, entity ID, timestamp, and changes
- Redact sensitive fields (passwords, tokens, PII) before persisting
- Add retention policies and archival for compliance
Audit Entry Structure
| Field | Type | Description | ||
|---|---|---|---|---|
id | str | Unique audit entry ID (UUID) | ||
timestamp | datetime | When the action occurred (UTC) | ||
user_id | str | Who performed the action | ||
action | str | CREATE, UPDATE, DELETE, ACCESS, LOGIN, etc. | ||
entity_type | str | The type of entity affected | ||
entity_id | str | The ID of the entity affected | ||
changes | `str \ | None` | JSON diff of old/new values (for updates) | |
ip_address | `str \ | None` | Client IP address | |
correlation_id | `str \ | None` | Request correlation ID |
Constraints
- NEVER update or delete audit records
- ALWAYS capture the acting user from the request authentication context
- ALWAYS use UTC timestamps (
datetime.now(timezone.utc)) - ALWAYS redact sensitive fields before persisting
- NEVER let audit failures break the primary operation (use try/except)
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/audit-backend-python/SKILL.md
Popularity
- 7-day trend score
- 5
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/congiuluc/my-awesome-copilot/audit-backend-python)