Skip to main content
OpenLIT guardrails let you analyse user input before it reaches your LLM. Each guardrail returns a structured JSON result with a score, verdict, classification, and explanation — so you can decide whether to block, flag, or pass through the request. The openlit.guard module provides four classes:

PromptInjection

Detects jailbreak and instruction-override attempts

SensitiveTopic

Flags potentially controversial or harmful subjects

TopicRestriction

Enforces a list of approved topics

All

Runs all three checks in a single call
Each guardrail supports two detection modes:
  • LLM-based detection: Uses OpenAI or Anthropic to evaluate the text. More accurate, requires an API key.
  • Regex-based detection: Uses custom regex rules you supply. Faster, no external API call required.

Prompt injection

Detects attempts to manipulate AI behaviour through malicious inputs, including jailbreaks, instruction overrides, and impersonation.

PromptInjection parameters

Injection categories

Sensitive topics

Detects discussions of potentially controversial or harmful subjects.

SensitiveTopic parameters

Sensitive topic categories

Topic restriction

Enforces approved topic boundaries. You define which topics are valid and which are invalid; the guardrail classifies every input accordingly.

TopicRestriction parameters

All detector

Runs prompt injection, sensitive topic, and topic restriction checks in a single call.

All parameters

Output format

Every detect() call returns a dict with this structure:

Supported providers

Evaluations

Programmatic hallucination, bias, and toxicity scoring

Tracing

Distributed traces for LLM calls and agent workflows

Destinations

Send telemetry to any OTel-compatible backend