Skip to content

LangChain / LangGraph

Attach Kaizen to any LangChain or LangGraph agent.

pip install "kaizen-security[langchain]"

Observe

Pass the callback handler. Every tool the agent calls is reported, so the Observer learns the agent's behavior and flags deviations.

from kaizen_security import Kaizen
from kaizen_security.integrations.langchain import KaizenCallbackHandler

kz = Kaizen(api_key="kz_live_...", agent="support-bot")

agent.invoke({"input": "..."}, config={"callbacks": [KaizenCallbackHandler(kz)]})

Block

LangChain swallows exceptions raised inside callbacks, so the callback is observe-only. To block a tool, wrap it. A blocked call returns a refusal to the agent instead of running.

from kaizen_security.integrations.langchain import guard_tool

safe_tools = [guard_tool(kz, t) for t in tools]

See it catch an attack

A support agent declares lookup_order and issue_refund. After normal work, a prompt injection tricks it into calling export_all_customers. Kaizen flags the undeclared call and the reasoning check judges it suspicious:

A LangChain support agent caught exporting the customer table

Runnable: examples/langchain/run.py.