Skip to main content

Prerequisites

Install and initialize the TypeScript SDK or Python SDK. The examples use that client as fw. Set OPENAI_API_KEY for the OpenAI model examples.

Add the callback handler

LangGraph.js can use the same LangChain callback handler through graph invocation config.
graph and state belong to the LangGraph application. Shadow-mode overrides for this handler are on the TypeScript SDK page.

Expected result

The callback handler inspects supported model and tool lifecycle events. Pass the handler to every model or graph call you intend to protect. In shadow mode, would-block calls continue. When enforcing, handle the SDK’s block exception at the application boundary.