AnthalePolicyViolationError when Anthale blocks the run.
If you already have an agent, the change is small: import the middleware, create it, and pass it to create_agent.
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
Add the middleware
Add metadata
This middleware already extracts the LangChain request and response messages it sends to Anthale. 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 AnthaleLangchainMiddleware is sent with every Anthale enforcement request created by that middleware.
For guidance on what belongs there, read Metadata & Logs.
What to expect
This integration protects the agent path itself. Use it when you want Anthale around model execution inside the agent, not only around one standalone chat model call.Verify the integration
- Send one benign agent request. The run should complete normally through the middleware.
- Send one request that your policy should block. The agent should raise
AnthalePolicyViolationError. - If the policy is configured to
redact, send content that should be sanitized and confirm the guarded run continues with sanitized content instead of the original value.
The middleware is wired correctly when normal agent runs still complete, blocked runs raise
AnthalePolicyViolationError, and redacted runs continue with sanitized content.Related repositories
anthale-python
Python SDK source, integrations, and examples.
anthale-openapi
OpenAPI contract used to generate Anthale API clients.