AnthalePolicyViolationError when Anthale blocks the guarded model call.
If you already have a LangChain chat model, the change is small: import the wrapper and wrap the model.
Before you start, create an Anthale API key and a policy, and make sure you already have an OpenAI API key. Use
Create an API Key for the Anthale key and First
Policy for the policy setup.
Install
Guard the chat model
Add metadata
This integration already extracts the LangChain request and response messages from the wrapped model call. Usemetadata only for application context Anthale cannot infer on its own, such as tenant, user, conversation, or request ID.
The keys below are examples. metadata can contain any fields your team uses for tracing and investigation.
metadata object you pass to guard_chat_model is sent with every Anthale enforcement request created by that wrapper.
For guidance on what belongs there, read Metadata & Logs.
What to expect
Useguard_chat_model when your LangChain flow is a runnable or chat model and you do not need agent middleware around tools. Anthale guards both the input and output path for the wrapped model.
Verify the integration
- Send one benign model call. The wrapped model should complete normally.
- Send one request that your policy should block. The wrapped model should raise
AnthalePolicyViolationError. - If the policy is configured to
redact, send content that should be sanitized and confirm the wrapped model continues with sanitized content instead of the original value.
The wrapper is wired correctly when normal model calls still complete, blocked calls raise
AnthalePolicyViolationError, and redacted calls continue with sanitized content.Related repositories
anthale-python
Python SDK source, integrations, and examples.
anthale-openapi
OpenAPI contract used to generate Anthale API clients.