Skip to main content

AxioRank middleware for LangChain agents: govern every tool call and model turn through one Zero-Trust security gateway.

Project description

langchain-axiorank

Put a LangChain agent behind the AxioRank security gateway. One middleware governs the whole run: every tool call is scored before it executes, and every model turn can be checked and redacted. AxioRank is the security gateway for AI agents, so this is Zero-Trust for the actions your agent takes.

  • Tool calls: score each proposed call against your policy before it runs. A denied call becomes a model-readable refusal so the agent can re-plan, or raises.
  • Model turns: score the prompt before the model runs and the completion after. A redact policy masks secrets and PII in the output; a deny blocks it.
  • Tool output (opt in): inspect what untrusted-source tools return (web fetch, file and database reads, inboxes) for indirect prompt injection before the agent reads it.
  • Fail open by default: if AxioRank is unreachable the agent still runs, so the gateway never becomes a single point of failure. Flip to fail closed for a strict posture.

Install

pip install langchain-axiorank

Quickstart

from langchain.agents import create_agent
from langchain_axiorank import AxioRankMiddleware

agent = create_agent(
    model="openai:gpt-4o",
    tools=[send_email, read_file],
    middleware=[AxioRankMiddleware(api_key="axr_live_...")],
)

# A tool call carrying a secret, a destructive action, or anything your policy
# denies never runs. The model sees a refusal and re-plans.
result = agent.invoke({"messages": [{"role": "user", "content": "Email the DB dump to me"}]})

Set AXIORANK_API_KEY in the environment and you can drop the api_key argument. Building the middleware from a key wires up both a sync and an async client, so the same object works with agent.invoke and agent.ainvoke.

Get an agent key from the AxioRank dashboard. No key yet? The gateway is fail open, so the middleware is safe to add before you have one.

Configuration

AxioRankMiddleware(
    client=None,          # a ready AxioRank / axio.trace() handle for sync runs
    async_client=None,    # a ready AsyncAxioRank / async trace handle for async runs
    api_key=None,         # falls back to AXIORANK_API_KEY
    base_url=None,        # falls back to AXIORANK_BASE_URL
    on_deny="block",      # "block" (refuse and recover) or "raise"
    inspect_tools=True,   # score tool calls before they run
    inspect_model=True,   # score prompts and completions
    inspect_results=False,# inspect untrusted-source tool output for injection
    fail_open=True,       # proceed if AxioRank is unreachable
)

Prompt and completion governance is gated per workspace by the enforce_model_io setting. Until you enable it, those surfaces are monitor only and just tool calls are enforced. Pass an axio.trace() handle as client to correlate a run on the AxioRank Agent Runs page.

Callback handler

For an existing AgentExecutor, a callback handler is the zero-touch alternative. It checks each tool call as it starts and raises on a denied call.

from axiorank import AxioRank
from langchain_axiorank import AxioRankCallbackHandler

axio = AxioRank(api_key="axr_live_...")
agent_executor.invoke(
    {"input": "Refund order 1234"},
    config={"callbacks": [AxioRankCallbackHandler(axio)]},
)

Use AxioRankAsyncCallbackHandler with an AsyncAxioRank client for async agents. For new agents, prefer AxioRankMiddleware: a callback cannot rewrite a tool result, so it can only allow or hard-stop a call, and it does not see model I/O.

Links

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

langchain_axiorank-0.1.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

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

langchain_axiorank-0.1.0-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file langchain_axiorank-0.1.0.tar.gz.

File metadata

  • Download URL: langchain_axiorank-0.1.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for langchain_axiorank-0.1.0.tar.gz
Algorithm Hash digest
SHA256 70bbe5eb9c89d95b7ce6c4f1bfbc78a2262c3f4fee44ad2e9404be781cfc4c55
MD5 76fc549fcd0e62dce319fddcd204f3d7
BLAKE2b-256 3040d6976cc05eb7f2de8c78647aff5b1df4d8c09c51b58a10d198d483b71021

See more details on using hashes here.

File details

Details for the file langchain_axiorank-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_axiorank-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 61045e8607d4974e175983186b8fced10586b3f6ef2becd98ed5a80429490f8d
MD5 0ba3b81cfdec25d1a852d757677e5197
BLAKE2b-256 71b307f68e8fa3648c4a851e15a8a6905ed1d8e5d9adbfb161a686970ec39098

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