curl --request POST \
--url https://api.trugen.ai/v1/ext/guardrail \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api-key>' \
--data @- <<EOF
{
"name": "Hate Speech Filter",
"category": "Content Safety",
"prompt": "Trigger when the user uses hateful, discriminatory, or abusive language toward a person or group.",
"response_message": "I'm sorry, but I can't help with that. Let's keep things respectful.",
"callback_url": "https://yourapp.com/webhooks/guardrail",
"is_active": true
}
EOFimport requests
url = "https://api.trugen.ai/v1/ext/guardrail"
payload = {
"name": "Hate Speech Filter",
"category": "Content Safety",
"prompt": "Trigger when the user uses hateful, discriminatory, or abusive language toward a person or group.",
"response_message": "I'm sorry, but I can't help with that. Let's keep things respectful.",
"callback_url": "https://yourapp.com/webhooks/guardrail",
"is_active": True
}
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: 'Hate Speech Filter',
category: 'Content Safety',
prompt: 'Trigger when the user uses hateful, discriminatory, or abusive language toward a person or group.',
response_message: 'I\'m sorry, but I can\'t help with that. Let\'s keep things respectful.',
callback_url: 'https://yourapp.com/webhooks/guardrail',
is_active: true
})
};
fetch('https://api.trugen.ai/v1/ext/guardrail', 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.trugen.ai/v1/ext/guardrail",
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' => 'Hate Speech Filter',
'category' => 'Content Safety',
'prompt' => 'Trigger when the user uses hateful, discriminatory, or abusive language toward a person or group.',
'response_message' => 'I\'m sorry, but I can\'t help with that. Let\'s keep things respectful.',
'callback_url' => 'https://yourapp.com/webhooks/guardrail',
'is_active' => true
]),
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.trugen.ai/v1/ext/guardrail"
payload := strings.NewReader("{\n \"name\": \"Hate Speech Filter\",\n \"category\": \"Content Safety\",\n \"prompt\": \"Trigger when the user uses hateful, discriminatory, or abusive language toward a person or group.\",\n \"response_message\": \"I'm sorry, but I can't help with that. Let's keep things respectful.\",\n \"callback_url\": \"https://yourapp.com/webhooks/guardrail\",\n \"is_active\": true\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.trugen.ai/v1/ext/guardrail")
.header("x-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"Hate Speech Filter\",\n \"category\": \"Content Safety\",\n \"prompt\": \"Trigger when the user uses hateful, discriminatory, or abusive language toward a person or group.\",\n \"response_message\": \"I'm sorry, but I can't help with that. Let's keep things respectful.\",\n \"callback_url\": \"https://yourapp.com/webhooks/guardrail\",\n \"is_active\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.trugen.ai/v1/ext/guardrail")
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\": \"Hate Speech Filter\",\n \"category\": \"Content Safety\",\n \"prompt\": \"Trigger when the user uses hateful, discriminatory, or abusive language toward a person or group.\",\n \"response_message\": \"I'm sorry, but I can't help with that. Let's keep things respectful.\",\n \"callback_url\": \"https://yourapp.com/webhooks/guardrail\",\n \"is_active\": true\n}"
response = http.request(request)
puts response.read_bodyCreate Guardrail
Creates a new guardrail rule for use within the TruGen AI system. Guardrails are workspace-scoped and reusable across agents - creating one does not attach it anywhere.
curl --request POST \
--url https://api.trugen.ai/v1/ext/guardrail \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api-key>' \
--data @- <<EOF
{
"name": "Hate Speech Filter",
"category": "Content Safety",
"prompt": "Trigger when the user uses hateful, discriminatory, or abusive language toward a person or group.",
"response_message": "I'm sorry, but I can't help with that. Let's keep things respectful.",
"callback_url": "https://yourapp.com/webhooks/guardrail",
"is_active": true
}
EOFimport requests
url = "https://api.trugen.ai/v1/ext/guardrail"
payload = {
"name": "Hate Speech Filter",
"category": "Content Safety",
"prompt": "Trigger when the user uses hateful, discriminatory, or abusive language toward a person or group.",
"response_message": "I'm sorry, but I can't help with that. Let's keep things respectful.",
"callback_url": "https://yourapp.com/webhooks/guardrail",
"is_active": True
}
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: 'Hate Speech Filter',
category: 'Content Safety',
prompt: 'Trigger when the user uses hateful, discriminatory, or abusive language toward a person or group.',
response_message: 'I\'m sorry, but I can\'t help with that. Let\'s keep things respectful.',
callback_url: 'https://yourapp.com/webhooks/guardrail',
is_active: true
})
};
fetch('https://api.trugen.ai/v1/ext/guardrail', 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.trugen.ai/v1/ext/guardrail",
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' => 'Hate Speech Filter',
'category' => 'Content Safety',
'prompt' => 'Trigger when the user uses hateful, discriminatory, or abusive language toward a person or group.',
'response_message' => 'I\'m sorry, but I can\'t help with that. Let\'s keep things respectful.',
'callback_url' => 'https://yourapp.com/webhooks/guardrail',
'is_active' => true
]),
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.trugen.ai/v1/ext/guardrail"
payload := strings.NewReader("{\n \"name\": \"Hate Speech Filter\",\n \"category\": \"Content Safety\",\n \"prompt\": \"Trigger when the user uses hateful, discriminatory, or abusive language toward a person or group.\",\n \"response_message\": \"I'm sorry, but I can't help with that. Let's keep things respectful.\",\n \"callback_url\": \"https://yourapp.com/webhooks/guardrail\",\n \"is_active\": true\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.trugen.ai/v1/ext/guardrail")
.header("x-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"Hate Speech Filter\",\n \"category\": \"Content Safety\",\n \"prompt\": \"Trigger when the user uses hateful, discriminatory, or abusive language toward a person or group.\",\n \"response_message\": \"I'm sorry, but I can't help with that. Let's keep things respectful.\",\n \"callback_url\": \"https://yourapp.com/webhooks/guardrail\",\n \"is_active\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.trugen.ai/v1/ext/guardrail")
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\": \"Hate Speech Filter\",\n \"category\": \"Content Safety\",\n \"prompt\": \"Trigger when the user uses hateful, discriminatory, or abusive language toward a person or group.\",\n \"response_message\": \"I'm sorry, but I can't help with that. Let's keep things respectful.\",\n \"callback_url\": \"https://yourapp.com/webhooks/guardrail\",\n \"is_active\": true\n}"
response = http.request(request)
puts response.read_bodyAuthorizations
Body
Human-readable label. Also used to derive the permanent key used at runtime (lowercased, punctuation replaced with underscores, deduplicated with a numeric suffix on collision).
"Hate Speech Filter"
The rule text the agent's LLM evaluates a user's message against to decide whether this guardrail applies.
"Trigger when the user uses hateful, discriminatory, or abusive language toward a person or group."
Free-text tag for grouping guardrails. No fixed list - any string is accepted, including an empty one.
"Content Safety"
Spoken to the user verbatim when this guardrail fires. If omitted, the guardrail falls back to a moderation-endpoint check instead of a canned response.
"I'm sorry, but I can't help with that. Let's keep things respectful."
Where a guardrail_triggered event is POSTed when this guardrail fires. Must be a well-formed http(s):// URL if present. Delivery is fire-and-forget - no retries.
"https://yourapp.com/webhooks/guardrail"
Set to false to exclude this guardrail from live conversations without deleting it.
Was this page helpful?