Documentation/Integration guide/Safety & Prompt Moderation with Custom Policies
Integration guide

Safety & Prompt Moderation with Custom Policies

Enterprise text and prompt safety filtering, custom keyword blocking, and policy guardrails.

4 min read
•Updated October 21, 2026

Commercial-Grade Safety Classifier

POST /v1/moderations classifies text inputs and generation prompts. The response includes classification metadata and supports custom policy rules.

Zero-Tolerance Safety Policies

Moderation applies configured safety policies and deterministic checks. Inspect results[].flagged and classification metadata, and test your own representative inputs; no classifier guarantees zero false positives or negatives.

Custom Keyword Rules & SHA-256 Caching

custom_blocked_words, custom_regex_patterns and custom_instructions add application rules. Repeated requests may use cached classifications; cache latency is not a guaranteed SLA.

Code Implementation

import os
import requests

BASE = "https://api.apimarketplace.com"
headers = {
    "Authorization": "Bearer " + os.environ["API_KEY"],
    "Content-Type": "application/json"
}

# 1. Standard prompt moderation check
response = requests.post(BASE + "/v1/moderations", headers=headers, json={
    "input": "A photorealistic portrait of an adult female astronaut",
    "model": "text-moderation-v1"
})
response.raise_for_status()
result = response.json()
print("Flagged:", result["results"][0]["flagged"])
print("Action:", result["results"][0]["action"])

# 2. Advanced moderation with custom tenant rules and blocked words
custom_response = requests.post(BASE + "/v1/moderations", headers=headers, json={
    "input": "Generate an ad referencing BrandX and internal codename ProjectTitan",
    "model": "text-moderation-v1",
    "custom_blocked_words": ["BrandX", "ProjectTitan"],
    "custom_instructions": "Block any references to competitor product names or unreleased hardware"
})
custom_response.raise_for_status()
custom_result = custom_response.json()
print("Custom Result Flagged:", custom_result["results"][0]["flagged"])
print("Category:", custom_result["results"][0]["category"])