LangChain · LangGraph
Put every tool a LangChain agent runs behind the AxioRank gateway, in TypeScript or Python.
Govern LangChain and LangGraph agents in both languages. Python has a dedicated
langchain-axiorank package built on agent middleware; TypeScript ships as a tool
guard in @axiorank/sdk.
npm install @axiorank/sdk @langchain/coreguardTools wraps a tools array so each call's arguments are scored before the
tool runs. The guarded tool keeps the original name, description, and schema,
making it a drop-in anywhere the original is used (LangChain or LangGraph).
import { AxioRank } from "@axiorank/sdk";
import { guardTools } from "@axiorank/sdk/langchain";
import { createReactAgent } from "@langchain/langgraph/prebuilt";
const axio = new AxioRank({ apiKey: process.env.AXIORANK_API_KEY! });
const agent = createReactAgent({
llm,
tools: guardTools(myTools, axio, { onDeny: "return" }),
});Why wrap, not a callback
LangChain.js runs callback handlers on an async queue and executes the tool
regardless of a handler throwing, so a callback can't reliably block a call.
Wrapping the tool scores it before it runs. onDeny: "return" lets the model
read the refusal as the tool result and re-plan.
Recommended: one middleware for the whole agent. AxioRankMiddleware scores
every tool call before it runs and every model turn as it happens, and it plugs
straight into create_agent. A denied tool call comes back as a model-readable
refusal so the agent re-plans; a redact policy masks secrets and PII in the
model's output.
pip install langchain-axiorankfrom 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_...")],
)Set AXIORANK_API_KEY and you can drop the api_key argument. Building from a key
wires up both a sync and an async client, so the same middleware works with
agent.invoke and agent.ainvoke. Pass an axio.trace() handle as client to
correlate the run on the Agent Runs page.
Prompt and completion governance
Tool calls are always enforced. Prompt and completion checks are gated per
workspace by enforce_model_io; until you enable it they run monitor-only. Set
inspect_results=True to also inspect the output of untrusted-source tools (web
fetch, file and database reads, inboxes) for indirect prompt injection.
Existing agents: a callback handler. On a classic AgentExecutor, attach
AxioRankCallbackHandler (from axiorank[langchain]) and every tool the agent
runs is checked first. A denied call raises AxioRankDeniedError, aborting the
step.
pip install "axiorank[langchain]"from axiorank import AxioRank
from axiorank.integrations.langchain import AxioRankCallbackHandler
axio = AxioRank(api_key="axr_live_...")
agent_executor.invoke(
{"input": "Refund order 1234"},
config={"callbacks": [AxioRankCallbackHandler(axio)]},
)For async agents, use AxioRankAsyncCallbackHandler with an AsyncAxioRank
client. A callback can allow or stop a call but cannot substitute a tool's output,
so a blocked call raises. To let the agent recover from a denial, use the
middleware above, or wrap a single tool with guard_tool (on_deny="return"):
from axiorank.integrations.langchain import guard_tool
safe_tool = guard_tool(my_tool, axio, on_deny="return")Next steps
- Framework integrations: the shared model and
axio.trace(). - Python SDK · TypeScript SDK: the underlying clients.
- Content-inspection engine: what gets flagged.