API Reference

Guard

Reliant Guard is a bidirectional AI safety layer. It filters user messages before they reach the AI provider (Input Guard), and validates AI responses before they reach the user (Output Guard). One API call replaces fragile prompt engineering with runtime enforcement in both directions.


POST /guard/chat

The recommended endpoint. Guard calls your configured AI provider internally, validates the response through all active layers, and returns the final safe response — in a single call.

http
POST /guard/chat X-Reliant-Key: rel_... Content-Type: application/json

Body

json
{ "user_message": "What's the price of your competitor?", "guard_id": "guard_ffd3913d70d48f029e8cf5f2", "user_id": "your-user-id" }
FieldTypeRequiredDescription
user_messagestringyesThe message sent by the end user
guard_idstringyesGuard config ID created in Dashboard → Guard
user_idstringyesYour User ID (Dashboard → Settings)
Provider and model are configured once in the Guard config — not passed per request. This keeps your integration minimal and your bot code clean.

Response

json
{ "allowed": false, "response": "I can only help with questions about our product.", "blocked_by": "topic", "block_reason": "Response discusses competitor pricing", "provider": "anthropic", "model": "claude-haiku-4-5-20251001", "guard_id": "guard_ffd3913d70d48f029e8cf5f2", "latency_ms": 312 }
FieldTypeDescription
allowedbooleanWhether the message passed all guard layers
responsestringThe final response to deliver to the user. Safe response if blocked.
blocked_bystring | nullSee values below. null if allowed.
block_reasonstring | nullHuman-readable explanation of why it was blocked
latency_msnumberTotal latency. Near-zero when input is blocked before the AI call.

blocked_by values

ValueLayerDescription
input_keywordInput GuardUser message matched a blocked keyword
input_patternInput GuardUser message matched a blocked regex pattern
input_piiInput GuardUser message contains PII (CPF, credit card, phone)
input_toxicInput GuardLLM detected hate speech, threats, or harassment
input_injectionInput GuardLLM detected a prompt injection or jailbreak attempt
topicOutput GuardAI response discussed a blocked or off-scope topic
dataOutput GuardAI response contained a blocked pattern or keyword
toneOutput GuardAI response violated tone rules
user_limitLimitsEnd-user exceeded their execution quota
project_limitLimitsProject exceeded its execution quota
token_limitLimitsEnd-user exceeded their token quota
Zero tokens on input blocks. Input Guard runs before the AI is called — so a blocked user message costs nothing in provider tokens.

POST /guard

Validate-only endpoint. Pass your own AI response for Guard to inspect. Use this when you already have the AI response and just need the validation layer.

json
{ "ai_response": "The AI-generated message to validate", "user_message": "What the user originally asked", "guard_id": "guard_ffd3913d70d48f029e8cf5f2", "user_id": "your-user-id" }

Guard layers

Guard runs two groups of layers in sequence: Input Guard (before the AI call) and Output Guard (after the AI call). A block at any layer short-circuits the rest.

Input Guard layers

These run on the user message before it is sent to the AI provider. A blocked input returns immediately — zero tokens consumed.

⬤ Input Keywords & Patterns

Fast string and regex matching on the user message. No LLM call. Configure input_blocked_keywords (exact match) and input_blocked_patterns (regex) in the Guard dashboard.

⬤ PII Blocker

Detects personal data in user messages before it reaches the AI. Built-in patterns cover CPF, credit card numbers, and Brazilian phone numbers. Enable with block_pii_input: true.

built-in PII patterns
CPF \d{3}\.?\d{3}\.?\d{3}-?\d{2} Credit card \d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4} BR phone (\+55)?\(?\d{2}\)?[\s-]?\d{4,5}[\s-]?\d{4}

⬤ Toxic Content & Prompt Injection (LLM)

Uses an LLM-as-judge (Haiku) to detect hate speech, threats, harassment, or jailbreak attempts in the user message. Enable independently with block_toxic_input and block_prompt_injection.

json — input blocked example
{ "allowed": false, "response": "Your message was blocked. Please rephrase.", "blocked_by": "input_injection", "block_reason": "Prompt injection attempt detected", "latency_ms": 18 }

Output Guard layers

These run on the AI response after the provider call, before delivery to the user.

◎ Topic Guard

Defines what the AI is allowed or not allowed to discuss. Uses LLM-as-judge to evaluate whether the response stays within the configured scope. Configure allowed_topics and blocked_topics in the Guard dashboard.

◫ Data Shield

Blocks responses containing sensitive data patterns or keywords. Runs instantly using regex and string matching — no LLM cost. Configure blocked_keywords and blocked_patterns (regex) in the Guard dashboard.

regex examples
// CPF (Brazil) \d{3}\.\d{3}\.\d{3}-\d{2} // Credit card \d{4}[\s-]\d{4}[\s-]\d{4}[\s-]\d{4} // Email [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}

◈ Tone & Compliance

Enforces brand voice and content policies. Uses LLM-as-judge to evaluate whether the response matches your configured tone_rules. Blocked phrases run instantly without LLM cost.


Integration example

Complete WhatsApp bot integration using /guard/chat:

javascript
// In your webhook handler (n8n, Make, or custom code) app.post('/webhook/whatsapp', async (req, res) => { const userMessage = req.body.message.text const userId = req.body.user.id // Single call — Guard handles AI + validation const guard = await fetch('https://reliant.api.br/guard/chat', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Reliant-Key': process.env.RELIANT_API_KEY, }, body: JSON.stringify({ user_message: userMessage, guard_id: process.env.GUARD_ID, user_id: process.env.RELIANT_USER_ID, }), }) const result = await guard.json() // result.response is always safe to send // If blocked: result.response = your configured safe_response // If allowed: result.response = validated AI response await sendWhatsAppMessage(userId, result.response) res.json({ ok: true }) })
Tip: The response field is always safe to deliver to the user — whether the request was allowed or blocked. You don't need to check allowed unless you want to log or handle blocked requests differently.

⬡ Reliant Limits

Limits control how many executions a project or an end-user can make within a period. When a limit is reached, the configured safe_response is returned automatically — no error, no broken app.

FieldTypeDescription
max_executions_per_periodnumberMax executions for the whole project per period
period_typestringhourly, daily, or monthly
limit_responsestringResponse returned when project limit is reached
max_executions_per_usernumberMax executions per end-user per period
user_period_typestringhourly, daily, or monthly
user_limit_responsestringResponse returned when user limit is reached

To enable per-user tracking, pass end_user_id in the /guard/chat request body — typically a phone number, user ID, or session token.

json — /guard/chat with end_user_id
{ "user_message": "What are your business hours?", "guard_id": "guard_...", "user_id": "your-user-id", "end_user_id": "+1-555-0100" // phone, user ID, or session token }

When a limit is hit, the response looks like this:

json — limit reached response
{ "allowed": false, "response": "You've reached your daily limit. Please try again tomorrow.", "blocked_by": "user_limit", "block_reason": "User limit reached: 50/50 per day", "guard_id": "guard_...", "latency_ms": 0 }
Zero cost when blocked. Limit checks run before the AI is called — so a blocked request costs nothing in tokens.

GET /guard/usage/:guard_id

Returns current period usage for a Guard — project total and top end-users by volume.

json — response
{ "period": "2026-05", "project_total": 8432, "top_users": [ { "end_user_id": "+1-555-0100", "count": 142, "period": "2026-05" }, { "end_user_id": "+1-555-0101", "count": 98, "period": "2026-05" } ] }

Guard config endpoints

GET /guard/configs

List all Guard configs for the authenticated project.

POST /guard/configs

Create a Guard config programmatically. Fields are split into Input Guard (run before the AI call) and Output Guard (run after).

json
{ "name": "Customer Support Bot", "provider": "anthropic", "model": "claude-haiku-4-5-20251001", "safe_response": "I can only help with questions about our product.", "user_id": "your-user-id", // ── Input Guard ───────────────────────────── "block_toxic_input": true, "block_prompt_injection": true, "block_pii_input": false, "input_blocked_keywords": ["spam", "promo"], "input_blocked_patterns": ["\\b(buy|sell)\\s+crypto\\b"], "input_safe_response": "Your message was blocked. Please rephrase.", // ── Output Guard ───────────────────────────── "allowed_topics": ["product support", "billing", "technical help"], "blocked_topics": ["competitors", "pricing details"], "blocked_keywords": ["password", "secret", "token"], "tone_rules": "Always be empathetic and professional. Never use aggressive language." }

Input Guard fields

FieldTypeDescription
block_toxic_inputbooleanBlock hate speech, threats, violence, and harassment via LLM judge
block_prompt_injectionbooleanBlock jailbreak and instruction-override attempts via LLM judge
block_pii_inputbooleanBlock messages containing CPF, credit card, or BR phone numbers
input_blocked_keywordsstring[]Block user messages containing any of these keywords (exact match)
input_blocked_patternsstring[]Block user messages matching any of these regex patterns
input_safe_responsestringMessage returned when input is blocked. Falls back to safe_response if empty.

PUT /guard/configs/:id

Update a Guard config.

DELETE /guard/configs/:id

Delete a Guard config.