API Reference

Complete documentation for the Guardrail scoring API. Pattern-based detection with configurable thresholds โ€” no gen-AI in the scoring path.

Authentication

All API requests (except /api/signup, /api/demo-check, and /api/health) require authentication via your API key.

Send your key via header (recommended)

X-Guardrail-Key: gr_live_your_key_here

Or via query parameter

GET /api/stats?key=gr_live_your_key_here

Admin endpoints (key management) require the master key set via GUARDRAIL_MASTER_KEY.

Base URL

https://guardrail-mvp-production.up.railway.app

Rate Limits

EndpointLimitWindow
/api/demo-check5 requestsPer hour, per IP
/api/checkUnlimitedWith valid API key
/api/signupUnlimitedIdempotent per email

Coming Soon Configurable per-key rate limits and usage quotas.

POST /api/check

Score an AI response for confidence, detect signals, extract claims, and route to a decision. Auth Required

Request Body

FieldTypeRequiredDescription
textstringRequiredThe AI-generated response text to score
userQuerystringOptionalThe original user question. Enables context-aware scoring: question-type detection, relevance analysis, scope checking, and refusal auditing
contextstringOptionalDomain context: general, medical, legal, financial, security, safety, mental_health, child_safety, nuclear. Default: general
userIdstringOptionalYour internal user ID for tracking

Example Request

curl -X POST https://guardrail-mvp-production.up.railway.app/api/check \
  -H "Content-Type: application/json" \
  -H "X-Guardrail-Key: gr_live_your_key" \
  -d '{
    "text": "The capital of France is Paris.",
    "userQuery": "What is the capital of France?",
    "context": "general"
  }'

Response (200 OK)

{
  "id": "a1b2c3d4-...",
  "confidence": 0.76,
  "decision": "deliver",
  "reasons": ["Hedged language", "Approximate quantification"],
  "context": "general",
  "effectiveContext": "general",
  "detectedContext": null,
  "timestamp": "2026-03-29T08:30:00.000Z",
  "excerpts": [
    {
      "signal": "Approximate quantification",
      "match": "approximately",
      "impact": "-8%"
    }
  ],
  "claims": [
    {
      "text": "The capital of France is Paris",
      "type": "claim",
      "verification": "unverified"
    }
  ]
}

Response Fields

FieldTypeDescription
idstringUnique check ID (UUID)
confidencefloatScore 0.0โ€“1.0 (higher = more confident)
decisionstringdeliver (โ‰ฅ0.75), flag (0.45โ€“0.74), or escalate (<0.45)
reasonsstring[]Human-readable signal labels that fired
contextstringThe context used for scoring
effectiveContextstringActual context used (may be auto-elevated)
detectedContextstring?Auto-detected domain (null if none detected)
excerptsobject[]Exact text matches + impact percentage per signal
claimsobject[]Extracted statements with type + verification status
queryAnalysisobject?Present when userQuery is provided. Contains questionType, relevanceScore, scopeRatio, and signals array

Claim Types

TypeDescription
claimFactual assertion (dates, stats, named entities)
opinionSubjective statement ("I think", "probably best")
instructionImperative/directive ("Run this", "You should")
questionInterrogative sentence
disclaimerSelf-hedging ("I don't have access", "as an AI")
fillerNon-substantive connective text

Verification Statuses

StatusMeaning
sourcedClaim has URL, DOI, or "according to [source]"
unverifiedFactual claim with no citation (โˆ’3% penalty, capped โˆ’15%)
self_hedgingDisclaimer/caveat โ€” informational only

POST /api/chat

Call Claude and score the response in one step. Supports page context from the chat widget for site-aware AI answers. Auth Required

Request Body

FieldTypeRequiredDescription
messagestringRequiredThe user's message to send to Claude
contextstringOptionalDomain context for confidence scoring (default: general)
systemPromptstringOptionalCustom system prompt for Claude
anthropicKeystringOptionalUse caller's own Anthropic key (their tokens). Falls back to server key if omitted
pageContextobjectOptionalScraped page data from the chat widget (see Auto Page Scraping)
userIdstringOptionalYour internal user ID for tracking

pageContext Object

FieldTypeDescription
titlestringPage title from document.title
urlstringFull page URL
descriptionstringMeta description or OG description
keywordsstringMeta keywords
headingsstring[]All h1โ€“h3 headings (e.g. "h1: Pricing")
bodyTextstringVisible page text (max 3,000 chars)
scrapedAtstringISO timestamp of when scraping occurred

Response (200 OK)

{
  "id": "a1b2c3d4-...",
  "fullText": "Claude's full response text...",
  "confidence": 0.78,
  "decision": "deliver",
  "reasons": [...],
  "inputTokens": 842,
  "outputTokens": 256,
  "hasPageContext": true
}

Returns 503 if no Anthropic API key is available (neither caller's nor server's).

POST /api/demo-check

Same as /api/check but requires no authentication. Rate-limited to 5 requests per hour per IP. Response includes "demo": true and "remaining": N.

POST /api/demo-chat

Keyless chat endpoint with pre-recorded responses. No LLM tokens consumed. Rate-limited to 10 requests per hour per IP. Returns a random domain-appropriate response scored by Guardrail. Used as fallback when no Anthropic key is available.

POST /api/signup

Self-serve API key generation. Idempotent โ€” same email returns same key.

Request Body

FieldTypeRequiredDescription
emailstringRequiredValid email address

Response (200)

{
  "key": "gr_live_a3b4c5d6...",
  "email": "you@example.com",
  "message": "Your API key has been created."
}

GET /api/developer/me

Get info about your API key โ€” request counts, decision breakdown, recent logs. Auth Required

Response (200)

{
  "key": "gr_live_xxx...xxx",
  "email": "you@example.com",
  "created": "2026-03-28T...",
  "requests": 42,
  "decisions": { "deliver": 30, "flag": 10, "escalate": 2 },
  "recentLogs": [...]
}

GET /api/stats

Aggregate platform stats. Auth Required

Response (200)

{
  "totalChecks": 1234,
  "deliverRate": 68.5,
  "avgConfidence": 0.72,
  "recentFlags": 12,
  "recentEscalations": 3
}

GET /api/logs

Recent scoring logs (newest first). Auth Required

Query Parameters

ParamTypeDefaultDescription
limitinteger20Number of logs to return (max 200)

GET /api/health

Health check โ€” no auth required.

{ "status": "ok" }

POST /api/keys

Create a new API key (admin only). Master Key Required

GET /api/keys

List all API keys (admin only). Master Key Required

DELETE /api/keys/:key

Revoke an API key (admin only). Master Key Required

Browser SDK

Drop-in JavaScript SDK available at:

<script src="https://guardrail-mvp-production.up.railway.app/sdk/guardrail.js"></script>

const gr = new Guardrail({
  apiKey: 'gr_live_xxx',
  context: 'medical',
  onEscalate: (r) => notifyHuman(r),
  onFlag: (r) => showDisclaimer(r),
});

const result = await gr.check(aiResponse);

Chat Widget

Drop-in embeddable AI chat with confidence scoring for any website. One script tag โ€” no build step, no dependencies.

Basic Integration

<!-- Paste before </body> -->
<script
  src="https://guardrail-mvp-production.up.railway.app/embed/widget.js"
  data-key="gr_live_xxx"
></script>

All Options

<script
  src="https://guardrail-mvp-production.up.railway.app/embed/widget.js"
  data-key="gr_live_xxx"
  data-context="general"
  data-title="AI Assistant"
  data-theme="dark"
  data-scrape="true"
  data-system-prompt="You are Acme Corp's support agent."
  data-welcome="Hi! Ask me anything about our products."
  data-placeholder="Ask anything..."
></script>

Data Attributes

AttributeDefaultDescription
data-keyrequiredYour Guardrail API key
data-scrape"true"Enable/disable auto page scraping
data-context"general"Domain context for scoring
data-title"AI Assistant"Widget header title
data-theme"dark""dark" or "light"
data-system-prompt""Extra instructions appended to Claude's system prompt
data-welcome"Hi! I'm your..."First message shown in chat
data-placeholder"Ask anything..."Input placeholder text

The widget calls /api/chat with your key. If no Anthropic key is set on the server, it falls back to /api/demo-chat automatically.

Auto Page Scraping

When data-scrape="true" (default), the widget automatically extracts structured content from the host page and sends it as pageContext with every chat message. This makes the AI site-aware โ€” it can answer questions about your website.

What Gets Scraped

DataSource
Titledocument.title
URLwindow.location.href
Description<meta name="description">
Keywords<meta name="keywords">
OG Tags<meta property="og:title">, og:description
HeadingsAll h1โ€“h3 elements (max 30)
Body TextVisible text content (max 3,000 characters)

What is NOT Scraped

Scripts, styles, SVGs, iframes, hidden elements, the widget's own UI, user inputs, cookies, localStorage, or data from other tabs.

Privacy

Text only. One-time scrape cached on load (no continuous monitoring). Body capped at 3,000 chars. Data is sent to your server only. Set data-scrape="false" to disable entirely.

tawk.to Integration

Score tawk.to chatbot responses via webhook, or connect Guardrail as an AI Assist Custom Tool.

POST /api/tawkto/webhook

Receives tawk.to chat events. Scores each agent/AI message and logs results. Requires X-Guardrail-Key header or ?key= query param.

https://guardrail-mvp-production.up.railway.app/api/tawkto/webhook?key=gr_live_xxx

Configure in tawk.to โ†’ Administration โ†’ Settings โ†’ Webhooks. Select Chat End and Chat Transcript events.

Response

{
  "processed": 3,
  "results": [
    { "text": "Bot response...", "confidence": 0.82, "decision": "deliver", "reasons": [] }
  ]
}

GET /api/tawkto/openapi.json

OpenAPI 3.0 schema for tawk.to AI Assist Custom Tool integration. Add this URL in tawk.to โ†’ AI Assist โ†’ Settings โ†’ Add Custom Tool (OpenAPI Server).

https://guardrail-mvp-production.up.railway.app/api/tawkto/openapi.json

MCP Server (Claude Desktop)

Guardrail has a native MCP server for use with Claude Desktop and other MCP-compatible clients. Now supports userQuery for context-aware scoring.

Install via npx (recommended)

npx guardrail-ai-mcp --key gr_live_xxx

Claude Desktop config (zero-setup)

{
  "mcpServers": {
    "guardrail": {
      "command": "npx",
      "args": ["guardrail-ai-mcp", "--key", "gr_live_xxx"]
    }
  }
}

Or download directly

Visit Developer Portal โ†’ "Download MCP Server" button, or:

curl -o guardrail-mcp.js https://guardrail-mvp-production.up.railway.app/api/mcp-download

Webhooks Coming Soon

Receive real-time notifications when responses are flagged or escalated. Configure a webhook URL and Guardrail will POST events to your endpoint.

Planned event types

EventWhen
response.flaggedConfidence 0.45โ€“0.74 (needs review)
response.escalatedConfidence < 0.45 (human required)
response.deliveredConfidence โ‰ฅ 0.75 (optional)

Planned webhook payload

{
  "event": "response.escalated",
  "timestamp": "2026-03-29T...",
  "data": {
    "id": "check-uuid",
    "confidence": 0.31,
    "decision": "escalate",
    "reasons": ["Knowledge cutoff disclaimer", "No real-time access"],
    "context": "financial",
    "textPreview": "I don't have access to real-time..."
  }
}

Integrations planned: Slack, PagerDuty, custom HTTP endpoints. Request access to the private beta.

Error Codes

StatusCodeDescription
400text is requiredMissing or empty text field in request body
401Missing API keyNo X-Guardrail-Key header or ?key= param
403Invalid API keyKey not found or revoked
404Key not foundAttempted to delete a non-existent key
429Demo limit reachedExceeded 5 demo requests per hour
500Internal errorServer-side failure (report to maintainer)

Signal Categories (60+ patterns)

CategoryPatternsWeight RangeExamples
Uncertainty80.08โ€“0.18hedged language, epistemic distancing, partial uncertainty
Knowledge Cutoff100.08โ€“0.22training cutoff, staleness hedge, verification nudge
Contradiction40.06โ€“0.14self-correction, position reversal, soft pivot
Evasion70.06โ€“0.12AI identity deflection, complexity deflection, explicit refusal
Hallucination90.08โ€“0.20ISBN/DOI fabrication, unattributed studies, precise statistics
Frustration50.06โ€“0.14repeated correction, abandonment signal, negative evaluation
Sycophancy40.04โ€“0.08flattery opener, excessive agreement, overconfident affirmation
Quality Bonuses8+0.02โ€“0.04numbered lists, code blocks, URLs, specific numbers

Domain Contexts

ContextRisk PenaltyAuto-detected?
general0%Default
medicalโˆ’25%โœ… Yes
legalโˆ’25%โœ… Yes
financialโˆ’20%โœ… Yes
securityโˆ’25%โœ… Yes
safetyโˆ’30%โœ… Yes
mental_healthโˆ’35%โœ… Yes
child_safetyโˆ’35%โœ… Yes
nuclearโˆ’35%โœ… Yes

When general is selected, Guardrail auto-scans for domain keywords and elevates the context automatically. The detectedContext field in the response shows what was detected.

Architecture Overview

Guardrail sits between your AI model and your users, scoring every response in real-time.

System Architecture

โ”€โ”€ Your Application โ”€โ”€
Any LLM โ†’ Your App
โ†“ AI response text
โ”€โ”€ Guardrail Platform โ”€โ”€
API Gateway โ†’ Scoring Engine (60+ signals) โ†’ Wikipedia Verification
โ†“ decision + confidence
โœ… Deliver (โ‰ฅ75%) โš ๏ธ Flag (45โ€“74%) ๐Ÿ”ด Escalate (<45%)

Integration Paths

IntegrationHow It WorksBest For
Browser SDKguardrail.js โ†’ /api/checkCustom apps with any LLM
Chat Widgetembed/widget.js โ†’ /api/chat + auto page scrapingAdding AI chat to any website
Chatflow / FlowiseCustom Tool โ†’ /api/checkNo-code chatbot builders
tawk.toWebhook โ†’ /api/tawkto/webhookMonitoring existing chatbot quality
MCP / Claude Desktopnpx guardrail-ai-mcp โ†’ /api/checkAI developers using Claude Desktop
Direct RESTcurl /api/checkAny language, any platform

Scoring Pipeline

1. Input: AI response text + context + userQuery
2. Scan: 60+ signal patterns across 7 categories
Uncertainty ยท Knowledge Cutoff ยท Contradiction ยท Evasion ยท Hallucination ยท Frustration ยท Sycophancy
3. Domain: Auto-detect context + apply risk penalty (โˆ’20% to โˆ’35%)
4. Quality: Assess structure (lists, code, URLs) โ†’ quality bonus (+2% to +10%)
5. Claims: Extract factual statements โ†’ count unverified (โˆ’3% each)
6. Query: If userQuery provided โ†’ relevance, scope, danger analysis
7. Verify: Cross-check claims against Wikipedia (optional)
8. Score: confidence = 0.82 + bonus โˆ’ penalty โ†’ clamp to 0.0โ€“1.0
9. Decide: deliver | flag | escalate

Full Mermaid architecture diagrams available at: Customer Architecture ยท Internal Architecture

Need help?

Read the FAQ ยท Try the Interactive Playground ยท Check the Changelog ยท View the Developer Portal