Guardrails AI × Sentiqra
Add Sentiqra as a structured classification step before or alongside generative-model guardrails. Use the LLM for reasoning and Sentiqra where you need a fixed classification taxonomy and versioned output.
Why This Integration Matters
Operational question this answers:
"How does Sentiqra fit into our LLM safety stack?"
As enterprises deploy LLM-based applications, the question "how does Sentiqra fit into our LLM safety stack?" becomes a top procurement objection for AI-native buyers. Guardrails AI is the leading open-source framework for adding programmable constraints to LLM outputs.
By integrating Sentiqra as a deterministic pre-classification layer in Guardrails AI, user prompts are classified for harmful content before reaching the LLM. This creates a two-layer defence: Sentiqra's deterministic taxonomy catches known harmful patterns with zero false negatives on flagged concepts, while the LLM handles creative generation on sanitised inputs.
This ties directly to Sentiqra's MCP positioning and the "grounding AI agents in deterministic evidence" pitch. This is the reference architecture that makes Sentiqra the essential first layer in any AI agent's safety stack.
Reference Architecture
┌───────────────────────────────────────────────────────────────────┐
│ Your Application │
│ │
│ Boundary 1 - input screening Boundary 2 - tool execution│
│ │
│ ┌──────────┐ ┌──────────────┐ ┌──────────┐ ┌────────────┐ │
│ │ User │──▶│ Sentiqra │ │ Agent │─▶│ Tool │ │
│ │ Prompt │ │ Pre-Classify │ │ proposes │ │ Gateway │ │
│ │ │ │ │ │ tool+args│ │ (yours) │ │
│ │ │ │ Harmful? │ └──────────┘ │ │ │
│ │ │ │ - Yes → block│ │ 1. actor + │ │
│ │ │ │ - No → pass │ │ args │ │
│ │ │ └──────────────┘ │ allowed?│ │
│ │ │ │ │ 2. gateway │ │
│ │ │ │ │ runs │ │
│ │ │ ▼ │ required│ │
│ │ │ ┌──────────────┐ │ checks │ │
│ │ │ │ LLM (GPT-4, │ │ 3. bound │ │
│ │ │ │ Claude, etc)│ │ approval│ │
│ │ │ └───────┬──────┘ └─────┬──────┘ │
│ │ │ │ ┌────▼─────┐ │
│ │ │◀── Response execute OR refuse│
│ └──────────┘ │
│ │
│ Screening is evidence, not authorization: a passed prompt does not │
│ grant the agent's proposed tool call - the gateway authorizes and │
│ re-checks the actual action + arguments before anything executes. │
└───────────────────────────────────────────────────────────────────────────┘
Data flow: User prompt enters → Sentiqra classifies it deterministically using the 200-concept taxonomy → if harmful, the guardrail blocks the request and returns a safe fallback → if not harmful, the prompt passes to the LLM for generation. When the application also lets the agent invoke tools, enforcement moves to a second boundary: the tool gateway - your code, not the model - evaluates the actual proposed action and arguments, invokes the required Sentiqra checks itself, applies authorization and policy, then executes or refuses. A clean screening result is never the permission to execute.
Working Code
Actual, tested, copy-pasteable code. Not pseudocode. Not aspirational.
Python - Guardrails AI + Sentiqra
import os
import requests
from typing import Any, Dict
from guardrails import Guard
from guardrails.validator_base import (
FailResult,
PassResult,
ValidationResult,
Validator,
register_validator,
)
@register_validator(name="sentiqra/harmful_content", data_type="string")
class SentiqraHarmfulContentValidator(Validator):
"""Block prompts that Sentiqra flags as harmful."""
def validate(self, value: str, metadata: Dict[str, Any]) -> ValidationResult:
response = requests.post(
"https://sentiqra.tech/v1/analyze",
headers={
"Authorization": f"Bearer {os.environ['SENTIQRA_API_KEY']}",
"Content-Type": "application/json",
},
json={
"text": value,
"language": metadata.get("language", "en"),
"analyzers": ["trust-safety"],
},
timeout=10,
)
signals = response.json()["signals"]
top = signals[0] if signals else None
if top and top["score"] > 0.7:
return FailResult(
error_message=f"Blocked by Sentiqra: {top['code']} (score: {top['score']})"
)
return PassResult()
# Attach the validator to a Guard (guardrails-ai >= 0.5 API)
guard = Guard().use(
SentiqraHarmfulContentValidator(on_fail="exception")
)
# Use with any LLM - Sentiqra checks the prompt first
from openai import OpenAI
llm = OpenAI()
def safe_complete(prompt: str, language: str = "en") -> str:
guard.validate(prompt, metadata={"language": language})
return llm.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": prompt}],
).choices[0].message.content
Action boundary - the gateway runs the check, not the agent
Prompt screening covers the input lane. For agent tool calls, the check must live in dispatch: the agent proposes tool + arguments, and your gateway authorizes the actor, invokes the required Sentiqra checks itself, and mints a bound, single-use approval - a benign prompt result never authorizes a privileged action. This wraps the sentiqra-agent-gateway.py reference implementation:
# tool calls the agent can propose - none execute without the gateway
EXECUTORS = {"send_email": send_email, "refund": issue_refund}
gateway = Gateway(load_policy("agent-policy.json"),
key=bytes.fromhex(os.environ["SENTIQRA_GATEWAY_KEY"]),
check=make_check("https://sentiqra.tech",
os.environ["SENTIQRA_API_KEY"]),
executors=EXECUTORS)
def dispatch(proposed: dict, session) -> dict:
# tenant + actor come from YOUR session - never from the analyzed text
context = {"tenant": session.tenant_id, "actor": session.agent_id}
decision = gateway.plan(proposed["tool"], proposed["arguments"], context)
if decision["decision"] != "approved":
return decision # denied: check failure, signal,
# or authorization - audited
# approval is bound to the exact args digest, actor, tenant, tool,
# policy version, and validity window; mutated args refuse at execute()
return gateway.execute(decision["approval"], proposed["tool"],
proposed["arguments"], context)
Install dependencies
pip install "guardrails-ai>=0.5" openai requests
Security & Compliance Posture
-
✓
EU AI Act - Risk Classification: Sentiqra's deterministic classification provides evidence that inputs were screened before reaching the LLM, which may support risk classification documentation under the AI Act.
-
✓
Deterministic Evidence: Unlike LLM-based safety filters (which are probabilistic and non-reproducible), Sentiqra's detection is deterministic - the same input under the same pinned configuration and output profile produces the same canonical analysis. This is critical for audit defensibility.
-
✓
Deterministic Coverage: Sentiqra's taxonomy-based approach is designed so that configured signals fire consistently for matching input - unlike probabilistic LLM-based filters, output is reproducible for the same input and configuration.
-
✓
MCP Integration: This reference architecture aligns with Sentiqra's MCP (Model Context Protocol) server, enabling AI agents to call Sentiqra as a deterministic safety tool.
-
✓
Audit Trail: Every blocked prompt has a Sentiqra detection record with the specific indicator, confidence, and configuration ID - providing evidence for AI safety audits.
Deployment Notes
Latency Impact
Sentiqra pre-classification targets <500ms (published p95 target) added to each prompt. For real-time chat applications, this is acceptable. For batch processing, the overhead is negligible. The LLM call itself typically takes 1–5 seconds.
Confidence Threshold
Set the Sentiqra confidence threshold based on your risk appetite. There is no universal cutoff - calibrate against your own labeled traffic and weigh the cost of a false positive against a false negative for your specific use case before automating actions.
Fallback Behaviour
If Sentiqra is unavailable (network error), configure the guardrail to either (a) fail closed and block the prompt, or (b) fail open and allow the prompt through with a logged warning. For regulated applications, fail closed is recommended.
Exception: checks a tool gateway requires before executing a privileged action must always fail closed - an analyzer outage is never permission to execute.
Cost
Guardrails AI is open source (Apache 2.0). The only cost is Sentiqra API calls - one per prompt. At Production tier pricing (~$0.0015/call; see pricing), screening 1M prompts/day costs roughly $1,500/day.
Multi-Language Support
Sentiqra supports 16 languages for Trust & Safety. Set the language parameter in the metadata to match the user's language for optimal detection performance.
Questions about this integration?
Talk to Solutions Engineering - first response within 1 business day.
Talk to Solutions Engineering →Related Integrations
Microsoft Presidio
Privacy & Data Protection
Run PII detection and redaction in your own environment before submitting text to Sentiqra. This pattern can reduce the amount of identifiable information sent downstream while keeping redaction policy under your control.
OpenTelemetry
Observability
Capture operational metadata such as latency, status, request identifiers, taxonomy versions, and result metadata using OpenTelemetry. The reference architecture avoids recording raw submitted text by default.
Redis
Streaming & Data Infrastructure
Cache repeated deterministic classifications when your workload contains identical requests. For reproducible behavior, cache keys should include the input and all versioned parameters that can affect the classification.