Skip to main content

Agent-agnostic compliance shim for SOX 404 policy enforcement via the ALCV Vault

Project description

Ledgix ALCV — Python SDK

PyPI Python 3.10+ License: MIT

Agent-agnostic compliance shim for SOX 404 policy enforcement. Intercepts AI agent tool calls, validates them against your policies via the ALCV Vault, and ensures only approved actions receive a cryptographically signed A-JWT (Agentic JSON Web Token).

Quick Start

pip install ledgix-python
# ledgix.yaml
# enforce:
#   - tool: "stripe_*"
#     policy_id: "financial-high-risk"
#   - tool: "*"
#     policy_id: "default"

import tools
import ledgix_python as ledgix

ledgix.configure(agent_id="payments-agent")
ledgix.auto_instrument(tools)

result = tools.stripe_refund(45, "Late package")
print(result)

auto_instrument() reads ledgix.yaml, ledgix.yml, or ledgix.json from the current working directory by default, wraps matching functions in place, and leaves unmatched functions alone.

Configuration

Set environment variables (prefix: LEDGIX_):

Variable Default Description
LEDGIX_VAULT_URL http://localhost:8000 Vault server URL
LEDGIX_VAULT_API_KEY "" API key for Vault auth
LEDGIX_VAULT_TIMEOUT 30.0 Request timeout (seconds)
LEDGIX_VERIFY_JWT true Verify A-JWT signatures
LEDGIX_JWT_ISSUER alcv-vault Expected A-JWT issuer
LEDGIX_JWT_AUDIENCE ledgix-sdk Expected A-JWT audience
LEDGIX_AGENT_ID default-agent Agent identifier

Or pass a VaultConfig directly:

from ledgix_python import LedgixClient, VaultConfig

config = VaultConfig(vault_url="https://vault.mycompany.com", vault_api_key="sk-...")
client = LedgixClient(config=config)

Manifest-driven auto-instrumentation

import tools
import ledgix_python as ledgix

ledgix.configure(agent_id="payments-agent")

# Auto-discover ledgix.yaml / ledgix.yml / ledgix.json from the CWD
wrapped = ledgix.auto_instrument(tools)

# Or pass an inline manifest
ledgix.auto_instrument(
    tools,
    manifest={"enforce": [{"tool": "stripe_*", "policy_id": "financial-high-risk"}]},
)

YAML manifests require pyyaml:

pip install ledgix-python[yaml]

Escape hatch

@ledgix.tool
def special_refund(amount: float):
    return ledgix.current_token()

@ledgix.tool(policy_id="override-policy")
def stripe_charge(amount: float):
    return ledgix.current_token()

Framework Adapters

LangChain

pip install ledgix-python[langchain]
from ledgix_python.adapters.langchain import LedgixCallbackHandler, LedgixTool

# Option 1: Callback handler (intercepts ALL tool calls)
handler = LedgixCallbackHandler(client)
agent = create_agent(callbacks=[handler])

# Option 2: Wrap individual tools
guarded_tool = LedgixTool.wrap(client, my_tool, policy_id="refund-policy")

LlamaIndex

pip install ledgix-python[llamaindex]
from ledgix_python.adapters.llamaindex import wrap_tool

guarded_tool = wrap_tool(client, my_function_tool, policy_id="refund-policy")

CrewAI

pip install ledgix-python[crewai]
from ledgix_python.adapters.crewai import LedgixCrewAITool

guarded_tool = LedgixCrewAITool.wrap(client, my_tool, policy_id="refund-policy")

Context Manager

from ledgix_python import VaultContext

with VaultContext(client, "stripe_refund", {"amount": 45}) as ctx:
    print(ctx.clearance.token)  # Use the A-JWT

# Async
async with VaultContext(client, "stripe_refund", {"amount": 45}) as ctx:
    print(ctx.clearance.token)

Error Handling

from ledgix_python import ClearanceDeniedError, VaultConnectionError, TokenVerificationError

try:
    result = process_refund(amount=5000, reason="...")
except ClearanceDeniedError as e:
    print(f"Blocked: {e.reason} (request: {e.request_id})")
except VaultConnectionError:
    print("Cannot reach Vault — fail-closed")
except TokenVerificationError:
    print("A-JWT signature invalid")

Development

git clone https://github.com/ledgix-dev/python-sdk.git
cd python-sdk
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
pytest tests/ -v --cov

Demo

python demo.py

License

MIT

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

ledgix_python-0.1.12.tar.gz (33.1 kB view details)

Uploaded Source

Built Distribution

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

ledgix_python-0.1.12-py3-none-any.whl (26.8 kB view details)

Uploaded Python 3

File details

Details for the file ledgix_python-0.1.12.tar.gz.

File metadata

  • Download URL: ledgix_python-0.1.12.tar.gz
  • Upload date:
  • Size: 33.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for ledgix_python-0.1.12.tar.gz
Algorithm Hash digest
SHA256 627490e82e5b5f39302c8099a470de787df046c4b4f4715c0285dbca279e100b
MD5 dde6fdf9547915ca692ce6045ce103e7
BLAKE2b-256 1ca9f8363c45b89a3823d7f5227beece91ff63c21755d8828d72cb7adfa03c72

See more details on using hashes here.

File details

Details for the file ledgix_python-0.1.12-py3-none-any.whl.

File metadata

  • Download URL: ledgix_python-0.1.12-py3-none-any.whl
  • Upload date:
  • Size: 26.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for ledgix_python-0.1.12-py3-none-any.whl
Algorithm Hash digest
SHA256 cd03379df3a3d6d327e919cbcfe7069f25fdd0c3859e03f5b8fea1e4a8f1bdc5
MD5 eb0c10dae3ed5419520fa9e5fffd2d28
BLAKE2b-256 e192773e414675b5626e74e8746779673e7ef4f56ecc5f683de07d74ab3d61bc

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 Pingdom Monitoring Sentry Error logging StatusPage Status page