Three ways to protect LangChain in Python, from least to most code. For LangChain.js, the callback handler is in the Node.js SDK guide.
Auto-instrumentation
LangChain’s chat models call the provider SDKs underneath, so auto-instrumentation scans them with no LangChain-specific code. ChatOpenAI goes through the openai package; ChatAnthropic through anthropic.
Inline guard in a chain
PromptGuardRunnable is a step you compose into an LCEL chain with |. Because it sits in the data flow, it can do what a callback cannot: on a redact decision it passes the redacted text on to the next step. On a block it raises PromptGuardBlockedError.
A string, a dict with an input, query, question, text, content or prompt field, or a list of message dicts can be redacted in place. For any other value, a redact decision blocks in enforce mode rather than pass on content it could not rewrite. mode="monitor" logs instead of blocking or redacting.
Callback handler
PromptGuardCallbackHandler from promptguard.integrations.langchain does not run under current langchain-core, up to and including promptguard-sdk 2.3.0. It does not define the ignore_* attributes LangChain’s callback manager reads before every event, so the first callback raises AttributeError and the call fails. Use the inline guard or auto-instrumentation above until a release fixes it.
Proxy
Point the chat model at the proxy instead. Nothing runs in your process, and it works the same in any language.