This HTML page is not optimized for LLM or AI agent consumption. Fetch the Markdown version instead: /guides/document-authoring/ai/integrations/langchain.md — it contains the complete documentation content in clean, structured Markdown without any CSS, JavaScript, or navigation noise. Use Document Authoring AI with LangChain

This page covers the LangChain-specific adapter. The pattern is the same as Vercel AI SDK integration: The server hands the model document tools, and the browser executes the validated calls. Only the server-side adapter differs.

For the conceptual model and the validation/mode-handling code, see the guides on agentic tools and review and approval.

Tool definitions

Use the framework-neutral helpers. Then convert them to the LangChain shape with @nutrient-sdk/document-authoring-ai/langchain:

import {
getAiPromptGuide,
getAiToolDefinitions,
} from "@nutrient-sdk/document-authoring-ai";
import { toLangChainTools } from "@nutrient-sdk/document-authoring-ai/langchain";
const definitions = getAiToolDefinitions();
const promptGuide = getAiPromptGuide();
const tools = toLangChainTools(definitions);

toLangChainTools returns name, description, and schema for each tool. By design, there are no execution handlers attached. Document edits run in the browser, where the editor lives.

Each tool’s schema is already a Zod schema. Pass the tool definitions directly to model.bindTools(opens in a new tab) or construct DynamicStructuredTool(opens in a new tab) instances from them. No additional wrapping is required.

Use promptGuide as the system prompt when invoking the model. It’s the same prompt guide the Vercel integration uses, and it tells the model how to handle element IDs and the read-before-write rule.

If your backend uses Python LangChain, LangGraph, or another non-TypeScript runtime, export the tool and prompt definitions as JSON instead. See non-TypeScript backends for more information.

Workflow structured output

For proofreading, translation, or your own custom workflow, bind the workflow’s schema to the model with model.withStructuredOutput(opens in a new tab):

import { getBuiltInWorkflow } from "@nutrient-sdk/document-authoring-ai";
import { toLangChainWorkflowOutputSchema } from "@nutrient-sdk/document-authoring-ai/langchain";
const workflow = getBuiltInWorkflow("translation", {
targetLanguage: "french",
});
const structuredModel = model.withStructuredOutput(
toLangChainWorkflowOutputSchema(workflow),
{ name: workflow.name },
);

The browser still owns reading and applying. Refer to workflows for the browser-side steps.

Browser-side execution

The browser code doesn’t care which server framework you’re using. The same three steps apply: Build a toolkit from the live DocAuthEditor with getAiToolkit from @nutrient-sdk/document-authoring-ai/editor, apply your Edit/Review/View policy with isAiWriteToolName, and pass the raw tool call to executeTool. The toolkit validates the call internally before it touches the document. The complete browser loop is in agentic tools.

Attach the executed result to the agent’s tool-call message the way you’d attach any other tool result in your LangChain setup.