Skip to main content

lexigram-ai-governance

AI governance for the Lexigram Framework — policy enforcement, audit trails, budget tracking


Overview

AI usage governance for the Lexigram Framework. Enforces budget caps, rate limits, and model access policies on LLM requests — with a full audit trail, soft-limit callbacks, TPM/cost sliding windows, and hot-reloadable configuration. Zero-config usage starts with sensible defaults.

Install

uv add lexigram-ai-governance

Quick Start

from lexigram import Application
from lexigram.di.module import Module, module

from lexigram.ai.governance import GovernanceModule
from lexigram.ai.governance.config import GovernanceConfig

@module(imports=[
    GovernanceModule.configure(
        GovernanceConfig(
            monthly_budget=50.0,
            enforce_budget=True,
            soft_limit_pct=0.8,
            rpm_limit=60,
            restricted_models=["gpt-4o"],
        )
    )
])
class AppModule(Module):
    pass

async with Application.boot(modules=[AppModule]) as app:
    # use app.container to resolve services
    ...

Configuration

Zero-config usage: Call GovernanceModule.configure() with no arguments to use defaults.

Option 1 — YAML file

# application.yaml
ai_governance:
  enabled: true
  monthly_budget: 100.0
  enforce_budget: true
  soft_limit_pct: 0.8
  rpm_limit: 60

Option 2 — Profiles + Environment Variables (recommended)

export LEX_AI_GOVERNANCE__MONTHLY_BUDGET=100.0
# Environment variables for each field

Option 3 — Python

from lexigram.ai.governance.config import GovernanceConfig
from lexigram.ai.governance import GovernanceModule

config = GovernanceConfig(
    monthly_budget=100.0,
    enforce_budget=True,
    soft_limit_pct=0.8,
    rpm_limit=60,
)
GovernanceModule.configure(config)

Config reference

Field Default Env var Description
enabled True LEX_AI_GOVERNANCE__ENABLED Master on/off switch for governance enforcement
monthly_budget None LEX_AI_GOVERNANCE__MONTHLY_BUDGET Monthly budget cap in dollars
enforce_budget True LEX_AI_GOVERNANCE__ENFORCE_BUDGET Hard-block requests when budget is reached
soft_limit_pct None LEX_AI_GOVERNANCE__SOFT_LIMIT_PCT Warn at this fraction of budget
max_request_cost None LEX_AI_GOVERNANCE__MAX_REQUEST_COST Per-request cost cap in dollars
rpm_limit None LEX_AI_GOVERNANCE__RPM_LIMIT Requests per minute cap
tpm_limit None LEX_AI_GOVERNANCE__TPM_LIMIT Tokens per minute cap
max_tokens_per_request None LEX_AI_GOVERNANCE__MAX_TOKENS_PER_REQUEST Hard token ceiling per request
restricted_models [] LEX_AI_GOVERNANCE__RESTRICTED_MODELS Models blocked for all users
model_allowlist {} LEX_AI_GOVERNANCE__MODEL_ALLOWLIST Per-user/role allowlist with glob patterns
model_denylist {} LEX_AI_GOVERNANCE__MODEL_DENYLIST Per-user/role denylist

Module Factory Methods

Method Description
GovernanceModule.configure(config) Configure with explicit config
GovernanceModule.stub(config) Minimal config for testing

Key Features

  • Budget enforcement: Monthly budget caps with soft-limit callbacks
  • Rate limiting: RPM and TPM sliding windows via BudgetTracker
  • Model access control: Per-user and per-role allowlist/denylist with glob patterns
  • Audit trail: Full governance decision recording via AIAuditStore
  • Hot reload: Update limits at runtime without restarting
  • Persistence backends: In-memory, Redis, and database backends

Testing

async with Application.boot(modules=[GovernanceModule.stub(
    GovernanceConfig(restricted_models=["gpt-4o"])
)]) as app:
    # your test code
    ...

Key Source Files

File What it contains
src/lexigram/ai/governance/module.py GovernanceModule.configure(), .stub()
src/lexigram/ai/governance/config.py GovernanceConfig
src/lexigram/ai/governance/services/manager.py AIGovernanceManager core logic
src/lexigram/ai/governance/budget/tracker.py BudgetTracker TPM / cost enforcement
src/lexigram/ai/governance/audit/ AIAuditStore, AIAuditEvent, query models
src/lexigram/ai/governance/persistence/persistence.py Persistence backends
src/lexigram/ai/governance/di/provider.py GovernanceProvider boot and registration

Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

lexigram_ai_governance-0.1.3007-py3-none-any.whl (115.3 kB view details)

Uploaded Python 3

File details

Details for the file lexigram_ai_governance-0.1.3007-py3-none-any.whl.

File metadata

File hashes

Hashes for lexigram_ai_governance-0.1.3007-py3-none-any.whl
Algorithm Hash digest
SHA256 f0532177cab286e31f4517e949f3509d7215725295be44f251a10161ee4d5f9b
MD5 334335d02f20da64e1b6b440c6376f47
BLAKE2b-256 18c4a02e365a5c8adc66fb4a0f59d29cb0d58924446914eac612f57dabb1f2b7

See more details on using hashes here.

Supported by

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