> ## Documentation Index
> Fetch the complete documentation index at: https://docs.promptguard.co/llms.txt
> Use this file to discover all available pages before exploring further.

# LangGraph

> Scan the model calls inside a LangGraph graph with auto-instrumentation, or guard a node input with the inline LangChain guard

A LangGraph node calls ordinary LangChain models, so the [LangChain](/integrations/frameworks/langchain) options carry over. Two of them work inside a graph today; both were checked against `langgraph` 1.2 and `langchain-core` 1.6 in Python.

## Auto-instrumentation

Call `init()` before the graph is built. Every model call made through a patched SDK is scanned, in whichever node it happens, sync or async. A block raises `PromptGuardBlockedError` out of `graph.invoke()`.

```python theme={"system"}
from typing import TypedDict

import promptguard
promptguard.init()  # reads PROMPTGUARD_API_KEY

from langchain_openai import ChatOpenAI
from langgraph.graph import END, START, StateGraph

llm = ChatOpenAI(model="gpt-5-nano")


class State(TypedDict):
    question: str
    answer: str


def answer(state: State) -> dict:
    return {"answer": llm.invoke(state["question"]).content}


graph = StateGraph(State)
graph.add_node("answer", answer)
graph.add_edge(START, "answer")
graph.add_edge("answer", END)
app = graph.compile()

app.invoke({"question": "What is prompt injection?"})
```

This scans what reaches the model. Tool calls and tool results are scanned only as part of the next model call's messages, not when the tool runs.

## Guarding a node's input

To scan, and redact, a value before a node uses it, invoke the inline guard inside the node. On a redact decision it returns the redacted value; on a block it raises.

```python theme={"system"}
from promptguard.integrations.langchain import PromptGuardRunnable

guard = PromptGuardRunnable().as_runnable()


def answer(state: State) -> dict:
    question = guard.invoke(state["question"])
    return {"answer": llm.invoke(question).content}
```

## Callback handler

Passing `PromptGuardCallbackHandler` in `config={"callbacks": [...]}` does not work in `promptguard-sdk` 2.3.0 and earlier: the handler fails under LangChain's callback manager (see [LangChain](/integrations/frameworks/langchain#callback-handler)), and LangGraph additionally calls `on_chain_start` with no serialized definition, which the handler does not accept. Use one of the two options above.

## Proxy

A `ChatOpenAI` pointed at the [proxy](/integrations/frameworks/langchain#proxy) works in a graph like anywhere else, in Python or LangGraph.js.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.