API Documentation
Integrate Mastiff Defense compliance guardrails into your Shopify store's chatbot.
Overview
Mastiff Defense is a compliance screening middleware — a three-layer AI guardrail that sits between your customers and your chatbot's LLM. Every message is screened before reaching the LLM, and every response is screened before reaching the customer.
There are two integration modes depending on your setup:
You have your own LLM or chatbot (Tidio, Gorgias, OpenAI, etc.). Use /screen/input and /screen/output to screen messages around your own LLM call.
You don't have an AI backend yet. Use /evaluate and Mastiff Defense screens the input and returns an AI-generated response in one call. You provide the chat interface.
Base URL:
Authentication
All requests require an API key passed in the request header. Your API key was provided when you installed the app. Each key is tied to your store.
If your key is missing or invalid the request returns status: "unauthorized". Contact support if you need a new key.
How It Works
Every message passes through three guardrail layers in order:
If any layer blocks the message, processing stops immediately — the remaining layers are skipped. The same three layers run on both the input (before your LLM) and the output (after your LLM).
Middleware ModePOST /screen/input
Run the customer's message through all three guardrail layers. If the result is clean, pass message to your LLM. If blocked, show the message field to the customer and stop.
Request Body
Response
POST /screen/output
Run your LLM's response through all three guardrail layers. If clean or redacted, show the message field to the customer. If blocked, show the message field (a safe fallback) instead of the LLM's response.
Request Body
Response
Response Statuses
| Status | Meaning | What to do |
|---|---|---|
| clean | Passed all layers | Use the message field as-is |
| blocked | Violated policy — stop here | Show message to customer (safe fallback) |
| redacted | Sensitive content removed | Show message (cleaned version) |
| error | Unexpected server error | Show fallback message, retry |
Always show the message field to the customer — it is always safe to display regardless of status.
Middleware Mode — Code Examples
POST /evaluate
For merchants who don't have their own LLM. Mastiff Defense screens the input, generates an AI response, screens the output, and returns the final result in a single call.
Request Body
Conversation history is optional but improves response quality for multi-turn conversations. It is never stored on our servers — send it with each request.
Response
Always show the response field to the customer regardless of status.
All-in-One Mode — Code Examples
Error Handling
Wrap all API calls in try/catch. If a request fails or times out, show a fallback message and retry.
Requests time out after 30 seconds. Average response time is under 1 second for keyword blocks, 1-3 seconds when semantic analysis runs.
Fail Mode
Fail mode controls what happens when Layer 3 (AI semantic analysis) becomes temporarily unavailable — for example, if semantic evaluation becomes temporarily unavailable. Layers 1 and 2 (keyword matching and policy rules) always run regardless.
If semantic analysis goes down, messages that passed Layers 1 and 2 are allowed through. Your chatbot keeps working. Suitable for most retail stores where uptime matters more than deep compliance coverage during outages.
If semantic analysis goes down, all messages are blocked until service recovers. Your chatbot stops responding. Suitable for stores handling sensitive topics (health, finance, legal) where compliance must be guaranteed at all times — even at the cost of availability.
Fail mode is configured per-tenant in your policy settings. The tradeoff is straightforward:
| Mode | During L3 outage | Best for |
|---|---|---|
| open | Chatbot keeps working (L1+L2 still protect you) | Retail, e-commerce, general customer service |
| closed | Chatbot stops responding entirely | Sensitive industries — health, finance, legal |
If no fail mode is configured, the platform defaults to open. Contact [email protected] to update your fail mode setting.
Tidio
Mastiff Defense cannot be used alongside Lyro. Lyro runs its own autonomous conversation loop and Tidio disables external flow integrations while it is active, making it impossible to screen messages in either direction. If you deactivate Lyro and switch to Tidio's standard Flow builder, we can walk you through the setup — email [email protected] and we'll get you configured.
Gorgias — Step-by-Step Setup
Gorgias is a helpdesk for Shopify stores. Mastiff Defense integrates with Gorgias to screen outgoing agent responses — logging anything sensitive before your support team sends it to a customer.
Use Middleware output mode (/screen/output) to screen agent responses. This catches sensitive pricing, internal notes, or policy violations in support replies and logs them to your Mastiff Defense audit trail.
Gorgias HTTP integrations are fire-and-forget — the integration sends a message to Mastiff Defense, but Gorgias cannot read the response back or act on it. Flagged messages are captured in your Mastiff Defense audit log for your team to review. The trigger fires on every new message — both customer messages and agent replies — so all traffic through a ticket is screened.
Step 1 — Create the HTTP Integration
In Gorgias, go to Settings → HTTP integration, then click the Manage tab. Click Add HTTP integration in the top right. Fill in the form as follows:
Leave OAuth2 disabled — authentication is handled by the X-API-Key header above. Click Add Integration.
Step 2 — Review flagged messages
When Mastiff Defense flags a message, it appears in the Recent Flags section of your store settings page. The log shows which guardrail triggered, the risk score, and a reason. If you need help reviewing anything, email [email protected].
If you need real-time blocking (stopping a reply before it reaches the customer), contact us — this requires a custom Gorgias API callback setup that we can configure for your store.
Step 3 — Test it
Open a test ticket in Gorgias and have an agent send a reply containing something that should be flagged (e.g., paste an internal pricing formula or a keyword from your policy). Within a few seconds the message should appear in your Mastiff Defense audit log marked as blocked or flagged.
Need Help Setting This Up?
Integration setup takes about 10 minutes for most stores, but every setup is a little different. If you get stuck at any step — wrong variable name, unexpected response, or the flow isn't firing — email us and we'll walk you through it.
Email [email protected] with your store domain and which platform you're using (Tidio, Gorgias, or something else). We'll respond within one business day.
Using a different platform — Zendesk, Freshdesk, Intercom, Re:amaze, or a custom chatbot? The same API works with any platform that can make HTTP requests. The code examples in the Code Examples section above apply directly.