AI Governance Control SDK · PyPI: aigc · v0.3.3
AIGC enforces governance over every AI model invocation, before and after the call. Policy-driven authorization, cryptographic audit artifacts, risk scoring, and a four-point gate system. Runs in your own infrastructure. No vendor lock-in.
// 01 overview
AI models make no guarantees by default. When your application calls a model, what policy governs that call? Who authorized it? What was the output allowed to contain? How do you prove it hours or weeks later?
AIGC (AI Governance Control) answers every one of those questions by sitting in the path of every invocation. It checks authorization before the call, validates output after it, scores risk, signs the evidence, and produces an immutable audit artifact. All of that runs in a single synchronous pipeline you own and deploy.
AIGC does not orchestrate, host, or own your model calls. You keep all of that. AIGC wraps your existing code with verifiable governance.
Every AI model invocation in your system produces a signed, timestamped audit artifact with SHA-256 checksums of both input and output. No call goes unrecorded.
// 02 architecture
A single call to enforce_invocation() runs every governance check in deterministic order. No step is skipped; no check is optional unless your policy explicitly allows it.
extends composition, validates against JSON Schema DSL.from aigc import enforce_invocation result = enforce_invocation({ 'policy_file': 'policies/my_policy.yaml', 'input': {'prompt': user_prompt}, 'output': {'response': model_response}, 'context': {'session_id': session_id}, 'model_provider': 'openai', 'model_identifier': 'gpt-4o', 'role': 'analyst', }) # result.audit_artifact (signed, immutable) # result.risk_score (numeric risk score) # result.passed (True if all checks passed)
// 03 split enforcement
AIGC's split enforcement separates authorization (before the call) from validation (after the output). Fail fast on policy violations without paying for an unnecessary model invocation.
Before your code calls the model, AIGC validates the request against policy. Policy violations stop the call entirely. No tokens consumed, no latency wasted.
pre_authorization & post_authorizationAfter the model returns, AIGC validates the output before it reaches your application. Output violating policy is rejected. It never reaches your application.
pre_output & post_output// 04 audit & evidence
Every invocation produces a structured audit record signed with HMAC-SHA256. Input and output are checksummed separately. The artifact is yours. AIGC writes it to your storage, your log stream, your audit database.
{
"artifact_id": "inv_01J8RKT...",
"timestamp": "2025-11-14T09:22:41.337Z",
"policy_version": "1.2.0",
"model_provider": "openai",
"model_identifier": "gpt-4o",
"role": "analyst",
"input_checksum": "sha256:e3b0c44298fc...",
"output_checksum": "sha256:a665a45920422...",
"risk_score": 0.12,
"risk_mode": "risk_scored",
"passed": true,
"signature": "hmac-sha256:f4c3b9..."
}
Input and output are checksummed independently. Tampering with either is detectable without re-running the model.
The full artifact is signed using HMAC-SHA256 with constant-time verification. Verification does not require the original model call.
Chain-of-custody lineage links related invocations. Correlate a downstream call to the upstream artifact that authorized it.
Per-role and per-session risk histories track pattern drift: a model that passes policy today but is trending toward violation thresholds.
// 05 extensibility
Need to check a blocklist, call your OPA policy server, or log to a SIEM before a call proceeds? EnforcementGates are your injection points. No forking required.
from aigc import EnforcementGate, GateContext class BlocklistGate(EnforcementGate): insertion_point = "pre_authorization" def check(self, ctx: GateContext) -> None: prompt = ctx.invocation["input"]["prompt"] if is_blocked(prompt): raise GateViolation( "Prompt matches blocklist" )
pre_authorizationpost_authorizationpre_outputpost_output// 06 risk scoring
Every invocation receives a numeric risk score derived from weighted policy factors. Three modes let you tune governance intensity per role, per model, or per call context.
Any risk score above threshold blocks the call. Zero tolerance. Use for regulated outputs, financial decisions, or medical contexts.
Risk score is computed and recorded in the audit artifact. The call is allowed, but the score is visible for downstream filtering or alerting.
Risk is surfaced as a warning in the artifact, never as a block. Use for observability during rollout, before switching to strict mode.
// 07 interactive labs
Ten interactive labs walk you through every AIGC capability. No model API key required for the core labs.
Test factor-based risk scoring. Adjust weights and modes, see how scores shift with different inputs, and watch enforcement outcomes change in real time.
Open lab →Generate HMAC-SHA256 signed audit artifacts and verify them. Tamper with fields to observe how signature validation fails.
Open lab →Build and inspect multi-invocation audit chains. Trace AuditLineage: see how downstream calls link back to the upstream artifact that authorized them.
Open lab →Use the extends DSL to compose policies from a base. See how role sets narrow (never widen) and how ambiguous merges are rejected.
Test policy loading, versioning, and schema validation. See how the loader resolves extends chains and validates against the JSON Schema DSL.
Open lab →Write and register custom EnforcementGates at all four insertion points. See gate failures propagate and observe how gates access full invocation context.
Open lab →View a live compliance summary across multiple invocations. Check pass/fail rates, risk distributions, and artifact counts by role.
Open lab →Apply governance to a RAG-style knowledge base. Enforce source constraints and validate retrieved content against postconditions before returning to the user.
Open lab →Side-by-side comparison: run the same prompt through a governed and an ungoverned path. See exactly what governance catches, and what slips through without it.
Open lab →Step through Phase A and Phase B hands-on. Trigger pre-call failures, watch output rejections, and see how split enforcement avoids unnecessary model costs.
Open lab →// 08 installation
extends.from aigc import enforce_invocation result = enforce_invocation({ 'policy_file': 'policies/basic.yaml', 'input': {'prompt': 'Summarize this document.'}, 'output': {'response': model_response}, 'context': {'request_id': 'req-001'}, 'model_provider': 'anthropic', 'model_identifier': 'claude-3-5-sonnet', 'role': 'analyst', }) if result.passed: print(result.audit_artifact['artifact_id']) # → 'inv_01J8RKT...'
policy_version: "1.0.0" roles: - analyst risk: mode: risk_scored threshold: 0.8 pre_conditions: required: - field: prompt type: string post_conditions: required: - field: response type: string
// 09 what's next
v0.9.0 adds multi-step workflow governance. A GovernanceSession wraps a series of invocations in a deterministic lifecycle. Every state transition is audited. Sessions can pause for approval, fail safely, and produce a final workflow artifact that correlates all constituent invocation artifacts.
The SDK will be renamed to AEGIS (Auditable Enforcement and Governance for Intelligent Systems) on release. The PyPI package aigc remains supported.
__exit__ never suppresses exceptionsINCOMPLETEFAILED artifact emitted, then re-raisesSessionPreCallResult is single-use. Replay attacks are rejected.from aigc import AIGC governance = AIGC() # open_session() is always instance-scoped with governance.open_session( policy_file="policies/review.yaml", ) as session: # Phase A: pre-call authorization pre = session.enforce_step_pre_call({ "policy_file": "policies/review.yaml", "input": {"prompt": prompt}, "output": {}, "context": {"caller_id": "demo"}, "model_provider": "anthropic", "model_identifier": "claude-sonnet-4-6", "role": "ai-assistant", }) # You call the model response = your_model_client.call(prompt) # Phase B: post-call validation + audit session.enforce_step_post_call(pre, {"result": response}) session.complete() # Workflow artifact on session.workflow_artifact after __exit__ # Source: github.com/nealsolves/aigc/tree/develop
Scaffold a governed workflow from minimal, standard, or regulated-high-assurance starter profiles. No hand-authored DSL required on the default path.
Validate your workflow manifest and policy composition before deployment. Surface constraint violations before they become runtime failures.
Diagnose a failed workflow session. Identifies the exact transition, gate, or constraint that caused failure, with specific steps to fix it.
Export workflow and invocation artifacts in operator or full-audit mode. Correlate invocation checksums back to their session context.
AIGC works alongside your existing AI infrastructure. No hosted service, no vendor lock-in. One Python package, one entry point, one audit artifact per call.
aigc will remain supported.