Skip to main content

langchain-axiorank

PyPI Python CI License: MIT

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

Contributing

Issues and pull requests are welcome at AxioRank/langchain-axiorank. Development happens in AxioRank's main repository and lands here with each release, so an accepted patch may be re-applied rather than merged directly.

License

MIT

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.1.tar.gz (9.3 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.1-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for langchain_axiorank-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a67699a22e30b7edf207b60e32c375a9134aa2d188f19ac4ad476e7a063aae44
MD5 8d576c0e0ef861a9610daf427e927188
BLAKE2b-256 33128e385d9ccd7274b8a21a97dda5db89cbaadd615fb57917d514bfdc0b494f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for langchain_axiorank-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b6ae90bdc97330d2c61298d4af12c42f05ab9fedafc24ea5348a7684d6fcc0a6
MD5 c24b4ff15a7edd233b7c0bc9bf227637
BLAKE2b-256 e5e748ffd04122c2c722880ae6db4727c22f955f69a588aabdbc236ae3d342b5

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page