Create Custom Rule
curl --request POST \
--url https://api.zerodrift.ai/api/policies/rules \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api-key>' \
--data '
{
"name": "<string>",
"type": "<string>",
"action": "<string>",
"severity": "<string>",
"prompt": "<string>",
"keywords": [
{}
],
"regex_pattern": "<string>",
"anchor": "<string>",
"near": [
{}
]
}
'import requests
url = "https://api.zerodrift.ai/api/policies/rules"
payload = {
"name": "<string>",
"type": "<string>",
"action": "<string>",
"severity": "<string>",
"prompt": "<string>",
"keywords": [{}],
"regex_pattern": "<string>",
"anchor": "<string>",
"near": [{}]
}
headers = {
"x-api-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'x-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: '<string>',
type: '<string>',
action: '<string>',
severity: '<string>',
prompt: '<string>',
keywords: [{}],
regex_pattern: '<string>',
anchor: '<string>',
near: [{}]
})
};
fetch('https://api.zerodrift.ai/api/policies/rules', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.zerodrift.ai/api/policies/rules",
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([
'name' => '<string>',
'type' => '<string>',
'action' => '<string>',
'severity' => '<string>',
'prompt' => '<string>',
'keywords' => [
[
]
],
'regex_pattern' => '<string>',
'anchor' => '<string>',
'near' => [
[
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-key: <api-key>"
],
]);
$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.zerodrift.ai/api/policies/rules"
payload := strings.NewReader("{\n \"name\": \"<string>\",\n \"type\": \"<string>\",\n \"action\": \"<string>\",\n \"severity\": \"<string>\",\n \"prompt\": \"<string>\",\n \"keywords\": [\n {}\n ],\n \"regex_pattern\": \"<string>\",\n \"anchor\": \"<string>\",\n \"near\": [\n {}\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-key", "<api-key>")
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.zerodrift.ai/api/policies/rules")
.header("x-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"<string>\",\n \"type\": \"<string>\",\n \"action\": \"<string>\",\n \"severity\": \"<string>\",\n \"prompt\": \"<string>\",\n \"keywords\": [\n {}\n ],\n \"regex_pattern\": \"<string>\",\n \"anchor\": \"<string>\",\n \"near\": [\n {}\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.zerodrift.ai/api/policies/rules")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"<string>\",\n \"type\": \"<string>\",\n \"action\": \"<string>\",\n \"severity\": \"<string>\",\n \"prompt\": \"<string>\",\n \"keywords\": [\n {}\n ],\n \"regex_pattern\": \"<string>\",\n \"anchor\": \"<string>\",\n \"near\": [\n {}\n ]\n}"
response = http.request(request)
puts response.read_bodyPolicy
Create Custom Rule
Create a customer-owned AI_SIGNAL, REGEX, or REQUIRE_NEAR rule
POST
/
api
/
policies
/
rules
Create Custom Rule
curl --request POST \
--url https://api.zerodrift.ai/api/policies/rules \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api-key>' \
--data '
{
"name": "<string>",
"type": "<string>",
"action": "<string>",
"severity": "<string>",
"prompt": "<string>",
"keywords": [
{}
],
"regex_pattern": "<string>",
"anchor": "<string>",
"near": [
{}
]
}
'import requests
url = "https://api.zerodrift.ai/api/policies/rules"
payload = {
"name": "<string>",
"type": "<string>",
"action": "<string>",
"severity": "<string>",
"prompt": "<string>",
"keywords": [{}],
"regex_pattern": "<string>",
"anchor": "<string>",
"near": [{}]
}
headers = {
"x-api-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'x-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: '<string>',
type: '<string>',
action: '<string>',
severity: '<string>',
prompt: '<string>',
keywords: [{}],
regex_pattern: '<string>',
anchor: '<string>',
near: [{}]
})
};
fetch('https://api.zerodrift.ai/api/policies/rules', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.zerodrift.ai/api/policies/rules",
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([
'name' => '<string>',
'type' => '<string>',
'action' => '<string>',
'severity' => '<string>',
'prompt' => '<string>',
'keywords' => [
[
]
],
'regex_pattern' => '<string>',
'anchor' => '<string>',
'near' => [
[
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-key: <api-key>"
],
]);
$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.zerodrift.ai/api/policies/rules"
payload := strings.NewReader("{\n \"name\": \"<string>\",\n \"type\": \"<string>\",\n \"action\": \"<string>\",\n \"severity\": \"<string>\",\n \"prompt\": \"<string>\",\n \"keywords\": [\n {}\n ],\n \"regex_pattern\": \"<string>\",\n \"anchor\": \"<string>\",\n \"near\": [\n {}\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-key", "<api-key>")
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.zerodrift.ai/api/policies/rules")
.header("x-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"<string>\",\n \"type\": \"<string>\",\n \"action\": \"<string>\",\n \"severity\": \"<string>\",\n \"prompt\": \"<string>\",\n \"keywords\": [\n {}\n ],\n \"regex_pattern\": \"<string>\",\n \"anchor\": \"<string>\",\n \"near\": [\n {}\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.zerodrift.ai/api/policies/rules")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"<string>\",\n \"type\": \"<string>\",\n \"action\": \"<string>\",\n \"severity\": \"<string>\",\n \"prompt\": \"<string>\",\n \"keywords\": [\n {}\n ],\n \"regex_pattern\": \"<string>\",\n \"anchor\": \"<string>\",\n \"near\": [\n {}\n ]\n}"
response = http.request(request)
puts response.read_bodyCreate a custom rule that belongs to your account. Supports
AI_SIGNAL,
REGEX, and REQUIRE_NEAR rule types. Requires a full-access API key.
Created rules start active. They run on Max (anchor_3_0_max) until you
train an adapter that Flagship can check. Copy rule_id from the response for
validation_scope.rules. See Enforce Content.
Request Body
The body is a discriminated union ontype. Shared fields:
string
required
Human-readable rule name
string
required
AI_SIGNAL, REGEX, or REQUIRE_NEARstring
required
fix or flagstring
required
do_not_send or send_with_cautionstring
Editable suggested replacement or warning guidance. Omit to allow warning
fallback;
null clears and suppresses warning fallback.string
Optional remediation guidance
AI_SIGNAL fields
string
required
AI instruction for the signal
array
required
Keyword gate (at least one string)
string
default:"document"
sentence, paragraph, or documentREGEX fields
string
required
Raw Python regex (max 512 chars)
REQUIRE_NEAR fields
string
required
Raw Python regex for the anchor pattern (max 512 chars)
array
required
Raw Python regex patterns checked near the anchor
integer
default:"100"
Character distance around the anchor
string
default:"either"
before, after, or eitherboolean
default:"false"
Case-insensitive matching
string
default:"document"
document or pageinteger
default:"1"
Minimum near-pattern hits required
Response
Returns the created custom rule (CustomRuleResponse), including rule_id,
source: "custom", active, timestamps, and type-specific fields.
Errors
| Status | Meaning |
|---|---|
400 | Invalid custom rule payload |
403 | Full-access API key required |
Example
Two request bodies for the same endpoint: aREGEX rule and an AI_SIGNAL
rule.
curl -X POST "https://api.zerodrift.ai/api/policies/rules" \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Block SSN patterns",
"type": "REGEX",
"action": "flag",
"severity": "do_not_send",
"regex_pattern": "\\b\\d{3}-\\d{2}-\\d{4}\\b"
}'
curl -X POST "https://api.zerodrift.ai/api/policies/rules" \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "No guaranteed returns",
"type": "AI_SIGNAL",
"action": "fix",
"severity": "do_not_send",
"prompt": "Flag language that guarantees investment returns.",
"keywords": ["guarantee", "guaranteed returns"],
"window": "sentence"
}'

