> ## 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](https://docs.promptguard.co/integrations/frameworks/langchain.md) options carry over. The samples below were run against `langgraph` 1.2 and `langchain-core` 1.7 in Python, with `promptguard-sdk` 2.4.

## 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

Pass `PromptGuardCallbackHandler` in the graph's config and it scans every model call made in any node. It needs `promptguard-sdk` 2.4.0 or later. The graph's `thread_id` is sent as the session id.

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

handler = PromptGuardCallbackHandler(mode="enforce")  # reads PROMPTGUARD_API_KEY

app.invoke(
    {"question": "What is prompt injection?"},
    config={"callbacks": [handler], "configurable": {"thread_id": "user-42"}},
)
```

## Proxy

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

## Next steps

> [card] [LangChain](https://docs.promptguard.co/integrations/frameworks/langchain.md)
>
> Auto-instrumentation, an LCEL guard, or the proxy

> [card] [Agent traces](https://docs.promptguard.co/security/agent-traces.md)
>
> Submit a full agent run to catch multi-step attacks

> [card] [Auto-instrumentation](https://docs.promptguard.co/integrations/auto-instrumentation.md)
>
> Which provider calls `init()` patches, and which it does not


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