EVE CoreGuard Python SDK
The eve-coreguard Python SDK provides a typed, ergonomic interface to the EVE CoreGuard governance decision engine. Install it from PyPI, configure your API key, and your first governance-enforced evaluation is running in under five minutes.
Contents
Installation
The SDK requires Python 3.9 or later. It has zero required dependencies — it uses only the Python standard library (urllib) for HTTP transport. Install from PyPI:
The package is published on PyPI: pypi.org/project/eve-coreguard.
To pin to a specific version (recommended for production):
For projects using pyproject.toml:
[project]
dependencies = [
"eve-coreguard>=0.1.0,<1.0.0",
]
Verify the installation:
Quick Start — 5 Lines
The following example evaluates a loan approval against the lending_v1 policy pack and prints the disposition. evaluate() takes keyword arguments directly — there is no request object to construct:
from eve_coreguard import CoreGuardClient
client = CoreGuardClient(api_key="eve_sk_...")
result = client.evaluate(
tenant_id="bank_001",
proposed_action={"type": "loan_approval", "amount": 250000},
model_output={"decision": "approve", "confidence": 0.91},
context={"credit_score": 580, "debt_to_income": 0.52},
policy_set="lending_v1",
)
print(result.verdict) # ALLOWED | BLOCKED | MODIFIED
API key security: Never hardcode your API key in source code. Load it from an environment variable: api_key=os.environ["COREGUARD_API_KEY"]. See Configuration for all available options.
Configuration
The CoreGuardClient accepts the following constructor parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
| api_key | str | required | Your EVE CoreGuard API key. Recommended to load from environment variable COREGUARD_API_KEY. |
| base_url | str | https://api.eveaicore.com | Base URL for the EVE CoreGuard API. Override for on-premises or private cloud deployments. |
| timeout | float | 30.0 | Request timeout in seconds. |
| max_retries | int | 3 | Maximum number of retries on transient 5xx errors. Uses exponential backoff. |
| raise_on_veto | bool | False | If True, verify() raises VetoError on a hard-veto or charter violation instead of returning a result. |
Load the API key from the environment rather than hardcoding it:
import os
from eve_coreguard import CoreGuardClient
client = CoreGuardClient(api_key=os.environ["COREGUARD_API_KEY"])
evaluate() Parameters
Call client.evaluate() with keyword arguments. They map directly to the POST /v1/decisions/evaluate request body.
| Parameter | Type | Description | |
|---|---|---|---|
| tenant_id | str | required | Organization/tenant identifier. Recorded on the decision certificate. |
| proposed_action | dict | required | The action being evaluated. Include type plus pack-specific fields (e.g. amount). |
| model_output | dict | recommended | The AI model's recommendation, e.g. {"decision": "approve", "confidence": 0.91}. |
| context | dict | optional | Domain-specific signals the policy evaluates (e.g. credit_score, debt_to_income). Defaults to empty dict. |
| policy_set | str | optional | Policy pack identifier. Defaults to "lending_v1". Discover others via list_policies(). |
| user | dict | optional | Actor context, e.g. {"id": "u_001", "role": "loan_officer"}. Defaults to an SDK client identity. |
| request_id | str or None | optional | Idempotency key. Auto-generated (UUID4) when omitted. |
| timestamp | str or None | optional | ISO 8601 timestamp. Defaults to the current UTC time. |
Full example
result = client.evaluate(
tenant_id="bank_001",
user={"id": "u_892", "role": "loan_officer"},
proposed_action={
"type": "loan_approval",
"applicant_id": "app_7823",
"amount": 85000,
},
model_output={"decision": "approve", "confidence": 0.88},
context={"credit_score": 712, "debt_to_income": 0.31, "employment_verified": True},
policy_set="lending_v1",
request_id="req_unique_0001", # idempotency key (optional)
)
EvaluationResult Fields
The evaluate() method returns a frozen EvaluationResult dataclass with the following structure (plus convenience properties .verdict, .allowed, .blocked, .decision_id, .signature, .audit_hash):
| Field | Type | Description |
|---|---|---|
| decision.status | str | Final disposition: "ALLOWED", "BLOCKED", or "MODIFIED". Also exposed as result.verdict. |
| decision.action | str | Resolved action, e.g. "deny_loan_approval". |
| risk.score | float | Risk score, 0.0–1.0. |
| risk.level | str | "LOW", "MEDIUM", or "HIGH". |
| risk.factors | list[str] | Human-readable risk factors that fired. |
| policy_violations | list[PolicyViolation] | Violations that fired. Each has .policy_id and .description. Empty for ALLOWED. |
| regulatory_impact | list[RegulatoryImpact] | Each maps a violation to a regulation: .regulation (e.g. ECOA), .risk, .severity. |
| counterfactual | Counterfactual or None | Thresholds that would have produced ALLOWED (.credit_score_required, .max_dti_allowed, .employment_required). |
| liability_prevented | LiabilityEstimate or None | Estimated exposure prevented (.estimated_exposure, .reason). |
| modifications | list[Modification] or None | Field edits applied for MODIFIED decisions (.field_name, .original_value, .modified_value, .reason). |
| audit | AuditRecord | The signed Decision Certificate. See Decision Certificates for the full schema. |
| audit.audit_id | str | Unique certificate identifier. Also exposed as result.decision_id. |
| audit.signature | str | HMAC-SHA256 signature over the canonical audit record. Also result.signature. |
Error Handling
The SDK uses a structured exception hierarchy. All exceptions inherit from CoreGuardError:
from eve_coreguard import (
CoreGuardClient,
CoreGuardError,
AuthError, # 401 — invalid or expired API key
PaymentRequiredError, # 402 — subscription past due / restricted
RateLimitError, # 429 — rate limit exceeded (has .retry_after)
PolicySetNotFoundError, # 404 — policy_set does not exist
VetoError, # raised by verify() when raise_on_veto=True
)
client = CoreGuardClient(api_key=os.environ["COREGUARD_API_KEY"])
try:
result = client.evaluate(tenant_id="bank_001", proposed_action=action)
except AuthError:
# Rotate API key; alert on-call
raise
except RateLimitError as e:
# Back off for e.retry_after seconds
time.sleep(e.retry_after)
except PolicySetNotFoundError:
# Unknown policy_set — check list_policies()
raise
except PaymentRequiredError:
# Subscription past due — inspect client.subscription_state
raise
except CoreGuardError as e:
logger.error(f"CoreGuard evaluation failed: {e} (status {e.status_code})")
raise
Output Verification & Policy Discovery
Beyond decision enforcement, the same client verifies AI-generated text through the 8-stage governance pipeline, and discovers the policy packs available to your tenant.
Verify AI output
vr = client.verify(
ai_output="The current prime rate is 8.5%.",
confidence=0.9,
domain="financial", # factual | financial | legal | medical | safety | creative | general
)
print(vr.passed, vr.blocked, vr.crd) # bool, bool, CRD score
if vr.blocked:
print(vr.veto.type, vr.veto.reason)
Discover policy packs
# List the catalog (optionally filter by regulatory domain)
for p in client.list_policies(domain="fair_lending"):
print(p.policy_id, p.version, p.rule_count)
# Fetch metadata for one pack
pack = client.get_policy("lending_v1")
print(pack.jurisdiction, pack.notes)
Advanced Usage
Batch Evaluation
The decision API evaluates one action per call. For high-throughput scenarios, evaluate concurrently with a thread pool — each call is an independent, idempotent HTTP request:
from concurrent.futures import ThreadPoolExecutor
from eve_coreguard import CoreGuardClient
client = CoreGuardClient(api_key=os.environ["COREGUARD_API_KEY"])
def check(app):
return client.evaluate(
tenant_id="bank_001",
proposed_action=app["action"],
context=app["context"],
policy_set="lending_v1",
)
with ThreadPoolExecutor(max_workers=8) as pool:
for app, res in zip(application_batch, pool.map(check, application_batch)):
if res.blocked:
handle_blocked(app, res)
Custom Policy Sets
Organizations on Enterprise plans may have custom policy packs deployed under organization-specific identifiers. Use them the same way as first-party packs — just pass the id as policy_set:
result = client.evaluate(
tenant_id="regional_bank_07",
policy_set="regional_lending_v1", # Custom pack for a regional lender
user={"id": "u_100", "role": "underwriter"},
proposed_action={"type": "loan_approval", "amount": 420000},
)
Offline Proof Verification
Every decision can be retrieved as a self-contained proof bundle and verified locally — no server call; it recomputes the SHA-256 content hash and checks the HMAC-SHA256 signature:
# Retrieve a proof bundle for a past decision
proof = client.get_proof("proof_abc123")
# Verify it offline with the server's signing key (static method, no network)
is_valid = CoreGuardClient.verify_proof(proof.raw, signing_key=key_hex)
print(f"Proof valid: {is_valid}")
# Export a batch of records for compliance review
export = client.export_audit(action_type="loan_approval", limit=100)
print(export.count, "records")
To verify certificates, chains, and ITI snapshots without any EVE CoreGuard client (the auditor/regulator path), use the dedicated offline verifier: pip install eve-governance.
Changelog
Offline-verification reliability fix.
- Fixes a critical bug where
fetch_public_key()failed because the base URL was never set, causing offline Ed25519 verification to silently fail. - Adds
test_evidence.pycovering round-trip, tamper, fail-closed, and auto-fetch paths. - Removes the unused
[async]install extra; honestverify_chain()docstring.
Independent offline decision-evidence verification.
- New
evidence.py:verify_decision_record(),fetch_public_key_pem(),recompute_content_hash()— recompute the SHA-256 content hash locally and check the Ed25519 signature with no server call. - New
verifyinstall extra (pip install "eve-coreguard[verify]", pullscryptography>=41). - LICENSE now included in the source distribution.
Policy catalog discovery.
client.list_policies(domain=...)andclient.get_policy(policy_id)for discovering available policy packs.- New typed
PolicyInfomodel (policy_id, version, domain, jurisdiction, rule_count). - SDK test suite grows to 33 tests.
Initial public release.
- Synchronous
CoreGuardClientwithevaluate()for decision enforcement. verify()for running AI output through the 8-stage governance pipeline.- Audit & proof retrieval:
get_proof(),get_recent_proofs(),export_audit(), and the staticCoreGuardClient.verify_proof()for offline HMAC verification. - Typed, frozen result models:
EvaluationResult,VerifyResult,ProofBundle. - Automatic retry with exponential backoff on 5xx errors.
- Exception hierarchy:
CoreGuardError,AuthError,PaymentRequiredError,RateLimitError,PolicySetNotFoundError,VetoError. - Zero required dependencies (stdlib
urllibtransport); 28 tests at launch. - Compatible with Python 3.9, 3.10, 3.11, 3.12, 3.13.
For upcoming releases and the full commit history, see the GitHub repository. Bug reports and feature requests are welcome via GitHub Issues or support@eveaicore.com.