import Anthale from 'anthale';
const client = new Anthale({
apiKey: process.env['ANTHALE_API_KEY'], // This is the default and can be omitted
});
const response = await client.organizations.policies.enforce(
'a90e34d6-41af-432f-a6ae-046598df4539',
{
direction: 'input',
messages: [{ content: 'Can you summarize the plot of Interstellar?', role: 'user' }],
},
);
console.log(response.action);import os
from anthale import Anthale
client = Anthale(
api_key=os.environ.get("ANTHALE_API_KEY"), # This is the default and can be omitted
)
response = client.organizations.policies.enforce(
policy_identifier="a90e34d6-41af-432f-a6ae-046598df4539",
direction="input",
messages=[{
"content": "Can you summarize the plot of Interstellar?",
"role": "user",
}],
)
print(response.action)curl --request POST \
--url https://api.anthale.com/organizations/policies/{policy_identifier}/enforce \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"direction": "input",
"messages": [
{
"role": "user",
"content": "Can you summarize the plot of Interstellar?"
}
],
"includeEvaluations": false,
"metadata": {}
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.anthale.com/organizations/policies/{policy_identifier}/enforce",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'direction' => 'input',
'messages' => [
[
'role' => 'user',
'content' => 'Can you summarize the plot of Interstellar?'
]
],
'includeEvaluations' => false,
'metadata' => [
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.anthale.com/organizations/policies/{policy_identifier}/enforce"
payload := strings.NewReader("{\n \"direction\": \"input\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Can you summarize the plot of Interstellar?\"\n }\n ],\n \"includeEvaluations\": false,\n \"metadata\": {}\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.anthale.com/organizations/policies/{policy_identifier}/enforce")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"direction\": \"input\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Can you summarize the plot of Interstellar?\"\n }\n ],\n \"includeEvaluations\": false,\n \"metadata\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.anthale.com/organizations/policies/{policy_identifier}/enforce")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"direction\": \"input\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Can you summarize the plot of Interstellar?\"\n }\n ],\n \"includeEvaluations\": false,\n \"metadata\": {}\n}"
response = http.request(request)
puts response.read_body{
"enforcerIdentifier": "8e9671f0-2365-4df9-bca0-2cc3cc61b0c9",
"action": "block",
"evaluations": [
{
"guardrailKey": "prompt-injection-protection",
"action": "block",
"score": 0.91,
"threads": [
{
"score": 0.88,
"messageIdentifier": 0,
"contentIdentifier": 1
}
],
"metadata": {}
}
]
}{
"error": {
"title": "Unauthorized",
"machineCode": "Unauthorized",
"message": "Authentication is required to access this resource."
}
}{
"error": {
"title": "<string>",
"machineCode": "<string>",
"message": "<string>",
"details": {}
}
}{
"error": {
"title": "TooManyRequests",
"machineCode": "TooManyRequestsError",
"message": "Rate limit exceeded. Please try again later."
}
}{
"error": {
"title": "Internal Server Error",
"machineCode": "InternalServerError",
"message": "An unexpected error occurred."
}
}Enforce a policy
Evaluates a set of messages against the specified policy and returns guardrail decisions.
import Anthale from 'anthale';
const client = new Anthale({
apiKey: process.env['ANTHALE_API_KEY'], // This is the default and can be omitted
});
const response = await client.organizations.policies.enforce(
'a90e34d6-41af-432f-a6ae-046598df4539',
{
direction: 'input',
messages: [{ content: 'Can you summarize the plot of Interstellar?', role: 'user' }],
},
);
console.log(response.action);import os
from anthale import Anthale
client = Anthale(
api_key=os.environ.get("ANTHALE_API_KEY"), # This is the default and can be omitted
)
response = client.organizations.policies.enforce(
policy_identifier="a90e34d6-41af-432f-a6ae-046598df4539",
direction="input",
messages=[{
"content": "Can you summarize the plot of Interstellar?",
"role": "user",
}],
)
print(response.action)curl --request POST \
--url https://api.anthale.com/organizations/policies/{policy_identifier}/enforce \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"direction": "input",
"messages": [
{
"role": "user",
"content": "Can you summarize the plot of Interstellar?"
}
],
"includeEvaluations": false,
"metadata": {}
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.anthale.com/organizations/policies/{policy_identifier}/enforce",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'direction' => 'input',
'messages' => [
[
'role' => 'user',
'content' => 'Can you summarize the plot of Interstellar?'
]
],
'includeEvaluations' => false,
'metadata' => [
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.anthale.com/organizations/policies/{policy_identifier}/enforce"
payload := strings.NewReader("{\n \"direction\": \"input\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Can you summarize the plot of Interstellar?\"\n }\n ],\n \"includeEvaluations\": false,\n \"metadata\": {}\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.anthale.com/organizations/policies/{policy_identifier}/enforce")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"direction\": \"input\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Can you summarize the plot of Interstellar?\"\n }\n ],\n \"includeEvaluations\": false,\n \"metadata\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.anthale.com/organizations/policies/{policy_identifier}/enforce")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"direction\": \"input\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Can you summarize the plot of Interstellar?\"\n }\n ],\n \"includeEvaluations\": false,\n \"metadata\": {}\n}"
response = http.request(request)
puts response.read_body{
"enforcerIdentifier": "8e9671f0-2365-4df9-bca0-2cc3cc61b0c9",
"action": "block",
"evaluations": [
{
"guardrailKey": "prompt-injection-protection",
"action": "block",
"score": 0.91,
"threads": [
{
"score": 0.88,
"messageIdentifier": 0,
"contentIdentifier": 1
}
],
"metadata": {}
}
]
}{
"error": {
"title": "Unauthorized",
"machineCode": "Unauthorized",
"message": "Authentication is required to access this resource."
}
}{
"error": {
"title": "<string>",
"machineCode": "<string>",
"message": "<string>",
"details": {}
}
}{
"error": {
"title": "TooManyRequests",
"machineCode": "TooManyRequestsError",
"message": "Rate limit exceeded. Please try again later."
}
}{
"error": {
"title": "Internal Server Error",
"machineCode": "InternalServerError",
"message": "An unexpected error occurred."
}
}Authorizations
Send an organization API key in the Authorization header as Bearer <api_key>.
Path Parameters
The policy identifier to enforce.
"a90e34d6-41af-432f-a6ae-046598df4539"
Body
Policy enforcer request schema.
Whether to evaluate input or output messages against the policy.
input, output "input"
Ordered list of messages that compose the conversation to evaluate.
1Show child attributes
Show child attributes
Whether to include evaluation details in the response.
false
Optional contextual metadata forwarded to guardrails.
Response
Successful Response
Policy enforcement response schema.
Identifier of the policy enforcer that processed the request.
"8e9671f0-2365-4df9-bca0-2cc3cc61b0c9"
Overall action decided by the policy (allow, detect, redact, block).
block, redact, detect, allow "block"
Per-guardrail evaluation results.
Evaluation payload for prompt injection guardrail.
- Option 1
- Option 2
- Option 3
- Option 4
Show child attributes
Show child attributes
Was this page helpful?