user and tool messages flowing through the chat model and raises InjectionDetectedError (in block mode) before the LLM call goes out.
Python
1
Install
2
Pass the guard as a callback
agent.py
BenchGuard implements the BaseCallbackHandler interface directly, so no wrapper class is needed. Pass it to any chain, agent, or .invoke() call that accepts callbacks.3
Handle injections
Works with
Any LangChain provider: Anthropic, OpenAI, Google, Mistral, Ollama, and custom LLMs. The callback attaches to the chat model, not the provider.TypeScript
1
Install
2
Wrap the callback
agent.ts
handleChatModelStart / handleLLMStart. asLangChainCallback() returns exactly that.What gets scanned
Duplicates are skipped. If the same tool output appears in multiple turns of a conversation, it’s only scanned once.
CrewAI
CrewAI uses the same LangChain callback protocol. PassBenchGuard directly to the Crew:
crew.py