AxonFlow governance integration for LiteLLM
Project description
axonflow-litellm
AxonFlow governance integration for LiteLLM. Enforce policies, audit LLM calls, and gate high-risk requests behind human approval — all through a drop-in wrapper around litellm.completion().
Installation
pip install axonflow-litellm
Quick Start
from axonflow_litellm import AxonFlowLogger, AxonFlowLoggerConfig, PolicyDeniedError
logger = AxonFlowLogger(AxonFlowLoggerConfig(
endpoint="http://localhost:8080",
client_id="my-app",
client_secret="...",
))
try:
response = logger.completion(
model="gpt-4o",
messages=[{"role": "user", "content": "Summarize quarterly earnings"}],
)
print(response.choices[0].message.content)
except PolicyDeniedError as e:
print(f"Blocked: {e.reason}")
How It Works
AxonFlowLogger provides two integration modes:
Governance Mode (recommended)
Use logger.completion() or logger.acompletion() as drop-in replacements for litellm.completion() / litellm.acompletion():
- Pre-check — sends the prompt to AxonFlow for policy evaluation
- HITL — if the policy returns
require_approval, creates a human-in-the-loop review request and polls until approved, rejected, or timed out - LLM call — delegates to LiteLLM (all providers supported)
- Audit — records the response to AxonFlow for observability
# Async (recommended for production)
response = await logger.acompletion(
model="claude-sonnet-4-6",
messages=[{"role": "user", "content": "..."}],
user_token="jwt-from-your-auth",
)
Audit-Only Mode
Register as a LiteLLM callback for observability without blocking:
import litellm
litellm.callbacks = [logger]
response = litellm.acompletion(model="gpt-4o", messages=[...])
In this mode, every LLM call is recorded to AxonFlow for audit trail. Policy denials are logged as warnings but cannot block the request (a LiteLLM SDK limitation — callback exceptions are silently swallowed).
Configuration
| Parameter | Default | Description |
|---|---|---|
endpoint |
(required) | AxonFlow agent URL |
client_id |
(required) | AxonFlow client identifier |
client_secret |
"" |
AxonFlow client secret |
default_user_token |
"anonymous" |
Token for policy evaluation when none provided |
tenant_id |
None |
AxonFlow tenant identifier |
fail_open |
True |
Allow LLM calls when AxonFlow is unreachable |
call_timeout_seconds |
5.0 |
Per-hook timeout for AxonFlow API calls |
breaker_failure_threshold |
5 |
Consecutive failures before circuit opens |
breaker_recovery_seconds |
30.0 |
Wait before attempting recovery probe |
enable_hitl_polling |
True |
Enable HITL approval flow for require_approval |
approval_poll_interval_seconds |
2.0 |
Polling interval for HITL status |
approval_max_wait_seconds |
300.0 |
Maximum wait for HITL decision |
extra_context |
{} |
Additional context sent with every pre-check |
Fail-Open vs. Fail-Closed
By default, fail_open=True: if AxonFlow is unreachable or times out, the LLM call proceeds normally. This ensures an AxonFlow outage does not break your application.
For high-stakes workloads where unapproved LLM calls must never proceed:
config = AxonFlowLoggerConfig(
endpoint="http://localhost:8080",
client_id="payments-service",
client_secret="...",
fail_open=False,
)
Sync vs. Async
Both litellm.completion() (sync) and litellm.acompletion() (async) are fully supported.
When registered via litellm.callbacks, sync hooks delegate to their async counterparts via asyncio.run(). This adds minor overhead (~1ms) per hook call in the sync path. For performance-critical sync workloads, use logger.completion() directly (governance wrapper) which amortizes the event loop creation.
If sync hooks are invoked inside a running event loop (unusual — e.g., sync callbacks from an async framework), a one-time RuntimeWarning is emitted directing you to acompletion().
Exceptions
| Exception | When |
|---|---|
PolicyDeniedError |
Policy denied the request |
ApprovalRejected |
HITL approval was rejected |
ApprovalTimeout |
HITL approval timed out |
All exceptions carry .reason (string) and .policies (list of policy IDs).
These exceptions do NOT extend litellm.exceptions.APIError — catch governance denials via PolicyDeniedError, not LiteLLM's exception hierarchy.
MCP Governance
LiteLLM is LLM-completion-focused. For MCP tool governance, use AxonFlow's MCP server directly.
Requirements
- Python >= 3.10
litellm>= 1.40axonflow>= 8.2.0
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file axonflow_litellm-1.0.1.tar.gz.
File metadata
- Download URL: axonflow_litellm-1.0.1.tar.gz
- Upload date:
- Size: 15.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6032c2314c37f881238bb43a2fb2abb4e8fbf6e4ba12f439091b742ff6787e58
|
|
| MD5 |
e7530c3a0961d06090f214adf3964e55
|
|
| BLAKE2b-256 |
a8d17162ea0a2238bcb195440ebfba0a303bdd15e9c1628352aa493e86add975
|
Provenance
The following attestation bundles were made for axonflow_litellm-1.0.1.tar.gz:
Publisher:
release.yml on getaxonflow/axonflow-litellm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
axonflow_litellm-1.0.1.tar.gz -
Subject digest:
6032c2314c37f881238bb43a2fb2abb4e8fbf6e4ba12f439091b742ff6787e58 - Sigstore transparency entry: 1616038913
- Sigstore integration time:
-
Permalink:
getaxonflow/axonflow-litellm@2449d8078230693bc7966bf517cad61aa1e3bb6f -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/getaxonflow
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@2449d8078230693bc7966bf517cad61aa1e3bb6f -
Trigger Event:
push
-
Statement type:
File details
Details for the file axonflow_litellm-1.0.1-py3-none-any.whl.
File metadata
- Download URL: axonflow_litellm-1.0.1-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42d1ad21b58a6a9d0bf1965e8ced19a3dec4ba3f296ab0c64b96237d3785f036
|
|
| MD5 |
757c0d82ecdfc3d5f878b2edef4b21df
|
|
| BLAKE2b-256 |
673987080c919eeec68e1a078d12333166eb9f8f8256ab49e638deb44e57d5ab
|
Provenance
The following attestation bundles were made for axonflow_litellm-1.0.1-py3-none-any.whl:
Publisher:
release.yml on getaxonflow/axonflow-litellm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
axonflow_litellm-1.0.1-py3-none-any.whl -
Subject digest:
42d1ad21b58a6a9d0bf1965e8ced19a3dec4ba3f296ab0c64b96237d3785f036 - Sigstore transparency entry: 1616038919
- Sigstore integration time:
-
Permalink:
getaxonflow/axonflow-litellm@2449d8078230693bc7966bf517cad61aa1e3bb6f -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/getaxonflow
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@2449d8078230693bc7966bf517cad61aa1e3bb6f -
Trigger Event:
push
-
Statement type: