---
title: "Use Document Authoring AI with LangChain"
canonical_url: "https://www.nutrient.io/guides/document-authoring/ai/integrations/langchain/"
md_url: "https://www.nutrient.io/guides/document-authoring/ai/integrations/langchain.md"
last_updated: "2026-06-12T18:57:15.089Z"
description: "Project Document Authoring AI tool definitions into LangChain tool metadata and keep document execution in the browser editor."
---

# LangChain integration

This page covers the LangChain-specific adapter. The pattern is the same as [Vercel AI SDK integration](https://www.nutrient.io/guides/document-authoring/ai/integrations/vercel-ai-sdk.md): 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](https://www.nutrient.io/guides/document-authoring/ai/agentic-tools.md) and [review and approval](https://www.nutrient.io/guides/document-authoring/ai/review-and-approval.md).

## Tool definitions

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

```ts

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`](https://docs.langchain.com/oss/javascript/langchain/models) or construct [`DynamicStructuredTool`](https://reference.langchain.com/javascript/langchain/index/DynamicStructuredTool) 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](https://www.nutrient.io/guides/document-authoring/ai/integrations/non-typescript-backends.md) 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`](https://docs.langchain.com/oss/javascript/langchain/structured-output):

```ts

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](https://www.nutrient.io/guides/document-authoring/ai/workflows.md) 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`](https://www.nutrient.io/api/document-authoring/types/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](https://www.nutrient.io/guides/document-authoring/ai/agentic-tools.md).

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

## Related pages

- [Convert document_authoring_ai["tools"] into the tool format expected by](/guides/document-authoring/ai/integrations/non-typescript-backends.md)
- [Vercel AI SDK integration](/guides/document-authoring/ai/integrations/vercel-ai-sdk.md)

