Skip to main content

Protocol Buffers schema for compliance-grade audit logging. Built for SOC2, HIPAA, and PCI environments.

Project description

lokryn-compliance-log-schema

Protocol Buffers schema for compliance-grade audit logging. Built for SOC2, HIPAA, and PCI environments. Works everywhere, optimized for AI/agent systems.

The Problem

There's no standard for compliance-grade audit logging. Everyone rolls their own. When you need to prove what happened, when, and why—especially with AI agents making autonomous decisions—you're stuck stitching together ad-hoc logs that weren't designed for auditors.

The Solution

A single, opinionated schema that covers:

  • Traditional audit events (login, file access, config changes)
  • AI/agent-specific events (tool calls, model inference, autonomous decisions)
  • Sensitivity classification for data handling policies
  • Outcome tracking for success/failure analysis

One format. Drop-in ready for any logging system. Built for compliance teams to actually use.


Installation

Python (PyPI)

pip install lokryn-compliance-log

Buf (For generating other languages)

Add to your buf.yaml:

deps:
  - buf.build/lokryn/compliance-log-schema

Then run:

buf mod update
buf generate

Schema Overview

EventType

What happened.

Event Description
EVENT_LOGIN User authentication
EVENT_LOGOUT Session termination
EVENT_FILE_ACCESS File read/write/delete
EVENT_POLICY_CHANGE Security policy modification
EVENT_PRIVILEGE_USE Elevated permission usage
EVENT_CONFIG_CHANGE System configuration change
EVENT_DATA_EXPORT Data leaving the system
EVENT_NETWORK_CONNECTION Network activity
EVENT_PROCESS_START Process execution
EVENT_PROCESS_STOP Process termination
EVENT_USER_MANAGEMENT User account changes
EVENT_RESOURCE_ACCESS Generic resource access

AI/Agent Events

Event Description
EVENT_TOOL_INVOCATION MCP tool call, function call, API invocation
EVENT_MODEL_INFERENCE LLM API call (completion, embedding, etc.)
EVENT_AGENT_DECISION Autonomous decision point (branching, action selection)
EVENT_DELEGATION Agent delegating to sub-agent or another system
EVENT_CONTEXT_ACCESS RAG retrieval, memory access, context window operations
EVENT_PROMPT_EXECUTION Prompt template execution
EVENT_GUARDRAIL_CHECK Safety/guardrail evaluation (pass/fail)

Severity

How important is this event. Follows RFC 5424 syslog levels.

Level Value When to Use
SEVERITY_DEBUG 1 Detailed debugging
SEVERITY_INFO 2 Normal operations
SEVERITY_NOTICE 3 Significant but normal
SEVERITY_WARNING 4 Something's off
SEVERITY_ERROR 5 Operation failed
SEVERITY_CRITICAL 6 System component failing
SEVERITY_ALERT 7 Immediate action needed
SEVERITY_EMERGENCY 8 System unusable

Outcome

Did it work?

Outcome Description
OUTCOME_SUCCESS Operation completed
OUTCOME_FAILURE_UNAUTHORIZED Authentication failed
OUTCOME_FAILURE_DENIED Authorization failed
OUTCOME_FAILURE_ERROR System/application error
OUTCOME_PARTIAL Partially completed

Sensitivity

How sensitive is the data involved?

Level Description
SENSITIVITY_PUBLIC No restrictions
SENSITIVITY_INTERNAL Internal use only
SENSITIVITY_CONFIDENTIAL Need-to-know basis
SENSITIVITY_RESTRICTED Regulatory/contractual restrictions
SENSITIVITY_HIGHLY_RESTRICTED Maximum protection (PII, PHI, PCI)

LogEntry Message

The core message structure:

message LogEntry {
  EventType event_type   = 1;
  Outcome outcome        = 2;
  Severity severity      = 3;
  string actor_id        = 4;   // Who did it (user, service, agent)
  string component       = 5;   // What system component
  string environment     = 6;   // prod, staging, dev
  string resource        = 7;   // What was accessed/modified
  string message         = 8;   // Human-readable description
  bytes payload          = 9;   // Structured data (JSON/CBOR)
  repeated string policy_tags = 10;  // Compliance tags (PCI, HIPAA, etc.)
  Sensitivity sensitivity = 11;
}

Usage Examples

Python

from lokryn_compliance_log import (
    LogEntry,
    EVENT_TOOL_INVOCATION,
    OUTCOME_SUCCESS,
    SEVERITY_INFO,
    SENSITIVITY_CONFIDENTIAL,
)

# Log an MCP tool call
log = LogEntry(
    event_type=EVENT_TOOL_INVOCATION,
    outcome=OUTCOME_SUCCESS,
    severity=SEVERITY_INFO,
    actor_id="agent-001",
    component="mcp-client",
    environment="production",
    resource="tools/database_query",
    message="Executed database query tool",
    payload=b'{"query": "SELECT * FROM users", "rows_returned": 42}',
    policy_tags=["SOC2", "data-access"],
    sensitivity=SENSITIVITY_CONFIDENTIAL,
)

# Serialize
data = log.SerializeToString()

Logging a Guardrail Check

from lokryn_compliance_log import (
    LogEntry,
    EVENT_GUARDRAIL_CHECK,
    OUTCOME_FAILURE_DENIED,
    SEVERITY_WARNING,
    SENSITIVITY_HIGHLY_RESTRICTED,
)

log = LogEntry(
    event_type=EVENT_GUARDRAIL_CHECK,
    outcome=OUTCOME_FAILURE_DENIED,
    severity=SEVERITY_WARNING,
    actor_id="agent-001",
    component="safety-filter",
    environment="production",
    resource="guardrails/pii-detection",
    message="PII detected in agent output, blocked",
    payload=b'{"rule": "ssn-pattern", "action": "block"}',
    policy_tags=["PII", "HIPAA"],
    sensitivity=SENSITIVITY_HIGHLY_RESTRICTED,
)

Logging an Agent Decision

from lokryn_compliance_log import (
    LogEntry,
    EVENT_AGENT_DECISION,
    OUTCOME_SUCCESS,
    SEVERITY_INFO,
    SENSITIVITY_INTERNAL,
)

log = LogEntry(
    event_type=EVENT_AGENT_DECISION,
    outcome=OUTCOME_SUCCESS,
    severity=SEVERITY_INFO,
    actor_id="agent-001",
    component="decision-engine",
    environment="production",
    resource="workflows/customer-support",
    message="Agent chose to escalate to human",
    payload=b'{"options": ["respond", "escalate", "defer"], "selected": "escalate", "confidence": 0.92}',
    policy_tags=["audit-trail"],
    sensitivity=SENSITIVITY_INTERNAL,
)

Why This Schema?

For Compliance Teams

  • Maps directly to SOC2, HIPAA, PCI audit requirements
  • Sensitivity levels match data classification policies
  • Policy tags let you filter by compliance framework
  • Outcome tracking shows attempted vs. successful actions

For AI/Agent Systems

  • First-class support for tool calls, model inference, and autonomous decisions
  • Tracks delegation chains (agent → sub-agent → tool)
  • Guardrail events create audit trail for safety checks
  • Context access events show what information agents used

For Developers

  • Single schema, multiple languages (Python, Go, TypeScript, etc.)
  • Protobuf means type safety and compact serialization
  • Drop-in ready for any logging backend
  • Works with Field Notes or your own system

Ecosystem

This schema is the foundation for:

  • lokryn-mcp - MCP client wrapper that auto-generates compliant logs
  • Field Notes - Tamper-evident audit logging with sub-second queries

License

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ https://www.apache.org/licenses/LICENSE-2.0.txt

Contributing

Issues and PRs welcome. For significant changes, open an issue first to discuss.


About Lokryn

Blue collar data tools for SMBs. Compliance-ready. No bloat. Fair pricing.

lokryn.com

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lokryn_compliance_log-0.2.0.tar.gz (19.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lokryn_compliance_log-0.2.0-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file lokryn_compliance_log-0.2.0.tar.gz.

File metadata

  • Download URL: lokryn_compliance_log-0.2.0.tar.gz
  • Upload date:
  • Size: 19.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for lokryn_compliance_log-0.2.0.tar.gz
Algorithm Hash digest
SHA256 370f8e99c7425f50129ce34308ba97b9b0b818be78ad611625e41c751dbd3a8a
MD5 6d1e11305124d5dc07c0aac3b751afcc
BLAKE2b-256 03822366deee37274f910405e29a125cdfb29fbbb48007ef7b8e1ee2669730b7

See more details on using hashes here.

Provenance

The following attestation bundles were made for lokryn_compliance_log-0.2.0.tar.gz:

Publisher: publish.yml on lokryn-llc/compliance-log-schema

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lokryn_compliance_log-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for lokryn_compliance_log-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3f414736ca0cbc9c8c1516661ceb85948902402419437eabb95b490c900c3526
MD5 2c30ef2c58c4d4c8ffb13d6b569b90d1
BLAKE2b-256 84557549ac84bec01cbf7575b33f919e9f6d46aec3dca1f30ede5ae83242cef6

See more details on using hashes here.

Provenance

The following attestation bundles were made for lokryn_compliance_log-0.2.0-py3-none-any.whl:

Publisher: publish.yml on lokryn-llc/compliance-log-schema

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page