Skip to main content

Overview

With the OpenLIT SDK, you can set up guardrails to keep your apps safe by handling tricky or risky prompts sent to AI models. We offer five main guardrails:

All

Detects and prevents risks by integrating all guardrails.

Prompt Injection

Detects malicious injection and jailbreaking attempts.

Sensitive Topics

Detects and flags discussions on potentially controversial subjects.

Topic Restriction

Detects and ensures conversations stay within approved topics.

PII / Data Redaction

Detects and redacts secrets, API keys, and personal data before it’s sent or traced.

Guardrails

Prompt Injection

Detects and prevents attempts to manipulate AI behavior through malicious inputs, including injection and jailbreak attempts. Opt for advanced detection using a Language Model (LLM) by specifying a provider and API key, or choose regex-based detection by providing custom rules without an LLM.#### How to Use

Usage

With LLM-based detection, you can use providers like OpenAI or Anthropic. Alternatively, you can specify a base_url with provider="openai" to use any provider that is compatible with the OpenAI SDK.

Supported Providers and LLMs

GPT-4o, GPT-4o mini
Claude 3.5 Sonnet, Claude 3.5 Haiku, Claude 3 Opus

Parameters

These parameters are used to set up the PromptInjection class:
These parameters are passed when you call the detect method to analyze a specific text:

Classification Categories

How it Works

  1. Input Gathering: Takes the text, categories, and optional custom rules or categories.
  2. Detection Choice:
    • Regex Detection: Uses regex if no provider is specified but custom rules are provided.
    • LLM Detection: Uses an LLM (OpenAI or Anthropic) if a provider is specified.
  3. Evaluation:
    • Regex: Applies custom rules to find prompt injections.
    • LLM: Sends a structured prompt to the LLM for analysis.
  4. JSON Output: Returns results with a score, verdict (“yes” or “no”), guard type, classification, and a brief explanation.

JSON Output:

The JSON object returned includes:
  • Score: Reflects the likelihood of prompt injection.
  • Verdict: “yes” if injection detected (score above threshold), “no” otherwise.
  • Guard: Marks the type of detection (“prompt_injection”).
  • Classification: Indicates the specific type of prompt injection detected.
  • Explanation: Offers a brief reason for the classification.

Sensitive Topics

Detects and flags discussions on potentially controversial or harmful subjects. Choose advanced detection using a Language Model (LLM) or apply regex-based detection by specifying custom rules without an LLM.

Usage

With LLM-based detection, you can use providers like OpenAI or Anthropic. Alternatively, you can specify a base_url with provider="openai" to use any provider compatible with the OpenAI SDK.

Supported Providers and LLMs

GPT-4o, GPT-4o mini
Claude 3.5 Sonnet, Claude 3.5 Haiku, Claude 3 Opus

Parameters

These parameters are used to set up the SensitiveTopic class:
These parameters are passed when you call the detect method to analyze a specific text:

Classification Categories

How it Works

  1. Input Gathering: Collects text, categories, and optional custom rules or categories.
  2. Detection Choice:
    • Regex Detection: Uses regex if no provider is specified but custom rules are available.
    • LLM Detection: Utilizes an LLM (OpenAI or Anthropic) if a provider is specified.
  3. Evaluation:
    • Regex: Applies custom rules to identify sensitive topics.
    • LLM: Sends a structured prompt to the LLM for evaluation.
  4. JSON Output: Provides results with a score, verdict (“yes” or “no”), guard type, classification, and a brief explanation.

JSON Output:

The JSON object returned includes:
  • Score: Indicates the likelihood of a sensitive topic.
  • Verdict: “yes” if a sensitive topic is detected (score above threshold), “no” otherwise.
  • Guard: Identifies the type of detection (“sensitive_topic”).
  • Classification: Displays the specific type of sensitive topic detected.
  • Explanation: Provides a concise reason for the classification.

Topic Restriction

Ensures that prompts are focused solely on approved subjects by validating against lists of valid and invalid topics. This guardrail helps maintain conversations within desired boundaries in AI interactions.

Usage

Supported Providers and LLMs

GPT-4o, GPT-4o mini
Claude 3.5 Sonnet, Claude 3.5 Haiku, Claude 3 Opus

Parameters

These parameters are used to set up the TopicRestriction class:
These parameters are passed when you call the detect method to analyze a specific text:

Classification Categories

How it Works

  1. Input Gathering: Collects text and lists of valid and invalid topics.
  2. Prompt Creation: Constructs a system prompt that includes specified valid and invalid topics for the LLM to assess.
  3. LLM Evaluation: Utilizes the LLM (OpenAI or Anthropic) to evaluate the text against the provided topic constraints.
  4. JSON Output: Provides results with a score, verdict (“yes” or “no”), guard type, classification, and a brief explanation.

JSON Output:

The JSON object returned includes:
  • Score: Indicates the likelihood of the text being classified as an invalid topic.
  • Verdict: “yes” if the text fits an invalid topic (score above threshold), “no” otherwise.
  • Guard: Identifies the type of detection (“topic_restriction”).
  • Classification: Displays whether the text is a “valid_topic” or “invalid_topic”.
  • Explanation: Provides a concise reason for the classification.

All Detector

Detects issues related to prompt injections, ensures conversations stay on valid topics, and flags sensitive subjects. You can choose to use Language Model (LLM) detection with specified providers or apply regex-based detection using custom rules.

Usage

With LLM-based detection, you can use providers like OpenAI or Anthropic. Alternatively, specify a base_url with provider="openai" to use any provider compatible with the OpenAI SDK.

Supported Providers and LLMs

GPT-4o, GPT-4o mini
Claude 3.5 Sonnet, Claude 3.5 Haiku, Claude 3 Opus

Parameters

These parameters are used to set up the All class:
These parameters are passed when you call the detect method to analyze a specific text:

Classification Categories

How it Works

  1. Input Gathering: Collects text, categories, and optional custom rules or categories.
  2. Detection Choice:
    • Regex Detection: Uses regex if no provider is specified but custom rules are provided.
    • LLM Detection: Utilizes an LLM (OpenAI or Anthropic) if a provider is specified.
  3. Evaluation:
    • Regex: Applies custom rules to detect prompt injections, topic restrictions, and sensitive topics.
    • LLM: Sends a structured prompt to the LLM for thorough analysis.
  4. JSON Output: Provides results with a score, verdict (“yes” or “no”), guard type, classification, and a brief explanation.

JSON Output:

The JSON object returned includes:
  • Score: Indicates the likelihood of an issue being present.
  • Verdict: “yes” if an issue is detected (score above threshold), “no” otherwise.
  • Guard: Identifies the type of detection (“prompt_injection”, “topic_restriction”, or “sensitive_topic”).
  • Classification: Displays the specific type of issue detected.
  • Explanation: Provides a concise reason for the classification.

PII / Data Redaction

Detects and redacts secrets, credentials, and personal data - API keys (OpenAI, Anthropic, AWS, GCP, GitHub, Stripe, Slack, and more), emails, phone numbers, SSNs, credit card numbers, IP addresses, bearer/basic auth headers, private keys, connection strings, and generic password=/secret= patterns - using built-in regex patterns, with support for your own custom patterns. Unlike the other guardrails, which return a yes/no verdict for you to act on, the PII guard is wired directly into openlit.init() and runs automatically around every instrumented LLM call - no separate detect() call needed.

Usage

With action="redact", matched text is replaced with [REDACTED:<label>] (e.g. [REDACTED:email]) both in the outgoing request and in the captured telemetry - so sensitive values never leave your stack or land in a trace.

Parameters

How it works

  1. Preflight: Before an instrumented LLM call is made, the guard scans the outgoing prompt/messages. If action="redact", matches are replaced before the request is sent - so the redacted text is what the model (and your telemetry) actually sees.
  2. Postflight: After a non-streaming response returns, the guard scans response content (e.g. choices[].message.content) the same way, on a best-effort basis.
  3. Combine with other guardrails: PII can be combined with PromptInjection, SensitiveTopic, TopicRestriction, and Moderation by passing multiple guards in the guards=[...] list - each runs as part of the same pipeline.
Streaming responses are not scanned postflight - redaction for streamed output content is a known limitation.

Deploy OpenLIT

Deployment options for scalable LLM monitoring infrastructure

Online Evaluations

Get started with evaluating your LLM responses in 2 simple steps on OpenLIT

Destinations

Send elemetry to Datadog, Grafana, New Relic, and other observability stacks