Skip to main content
LangChain runs a tool through BaseTool.invoke. infy.integrations.langchain.govern wraps each of your tools at that chokepoint so every call first asks infy governance whether the action is allowed. A denied or unapproved action never runs. The model receives the block reason as the tool output instead, and every decision is written to the tamper-evident audit chain. The wrapped tools are StructuredTool instances with the same name, description, and args schema, so they are drop-in replacements. Pass them to create_react_agent, AgentExecutor, or bind_tools exactly as you pass your originals. Your agent code does not change.
This adapter only needs langchain-core. Install it with pip install langchain-core.

How it works

govern returns one governed tool per input tool. When the agent invokes a governed tool:
1

Check the policy and risk

The wrapper calls governance.before_tool with the tool’s metadata (name, verb, risk tier, side effect) and the call arguments.
2

Block or run

If the decision is not allowed, the wrapper returns [Infyrence governance] <message> as the tool result and the underlying tool never runs. If allowed, it calls the real tool.invoke.
3

Record the outcome

On an allowed call, governance.after_tool records the result. Every decision, allowed or denied, lands in the audit chain.

The risk map

The risk argument maps a tool name to its risk profile: verb, risk_tier, and side_effect. The risk engine reads these to tier each call.
A tool not named in risk is treated as conservatively high-risk and side-effecting ({"verb": "EXECUTE", "risk_tier": "high", "side_effect": True}). Governance fails safe on an unprofiled tool rather than waving it through. Override this fallback with the default argument.

Full example

This wires three real LangChain tools through governance and drives them the way an agent would. Reads run, the destructive delete is denied by policy and never executes, and the high-risk deploy pauses for a human before it is allowed.
Because the agent calls tool.invoke just like this loop does, pointing a real LLM at these same governed tools behaves identically. The delete_database call returns a governance block message and never executes, while the allowed and denied decisions are all recorded in the hash-chained audit that audit.verify() confirms was not altered.
The runnable version of this example lives at examples/langchain_governance_demo.py. Run it with python examples/langchain_governance_demo.py.

Governance overview

Policy, risk tiering, approval, and the audit chain.

Durable approval

Suspend a run for a human and resume it later, TOCTOU-safe.