AnthalePolicyViolationError when Anthale returns block.
If you already have an OpenAI client, the change is small: import the guard and wrap the client.
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 OpenAI client
Add metadata
This integration already extracts the OpenAI request and response messages for you. 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_openai_client is sent with every Anthale enforcement request created by that guarded client.
For guidance on what belongs there, read Metadata & Logs.
What to expect
The guarded OpenAI client stops before the request proceeds when Anthale returnsblock. You do not inspect response.action here because the integration raises an exception instead.
Verify the integration
- Send one benign request. The guarded client should complete the model call normally.
- Send one request that your policy should block. The guarded client should raise
AnthalePolicyViolationErrorbefore the model call completes. - If the policy is configured to
redact, send content that should be sanitized and confirm the guarded client continues with sanitized content instead of the original value.
The integration is wired correctly when safe requests still complete, blocked requests raise
AnthalePolicyViolationError, and redacted requests continue with sanitized content.Related repositories
anthale-python
Python SDK source, integrations, and examples.
anthale-openapi
OpenAPI contract used to generate Anthale API clients.