API Reference

Welcome to the AI Sentinel API reference documentation. This page provides detailed information about the public classes, methods, and functions available in the package. The API is organized into three main modules: core components, guard systems, and LLM clients.

Note

All examples assume you have already installed AI Sentinel.

Core Components

The core module provides fundamental data structures and utilities used throughout AI Sentinel.

ai_sentinel.core.LLMResponse(*, content, ...)

Response from an LLM Provider

Example Usage:

from ai_sentinel.core import LLMResponse

# Create a response object
response = LLMResponse(
    content="Sample response",
    model="gpt-4"
)

Guard Systems

The guards module contains the toxicity detection and analysis components, which are the primary tools for content moderation.

ai_sentinel.guards.toxicity_guard.ToxicityResult(*, ...)

Structured output from LLM toxicity assessment

ai_sentinel.guards.toxicity_guard.ToxicityCategories(value)

Specify Toxicity Categories

ai_sentinel.guards.toxicity_guard.ToxicityScore(value)

Toxicity severity levels

Example Usage:

from ai_sentinel.guards import ToxicityGuard
from ai_sentinel.guards.toxicity_guard import ToxicityCategories

# Initialize the guard
sample_client = "your_client_here"  # Replace with actual client
guard = ToxicityGuard(client=sample_client)

# Analyze text
result = guard.analyze("Your text here")

# Access results
print(result.is_toxic)
print(result.categories)
print(result.scores)

LLM Clients

The LLM module provides interfaces to various Language Model providers. Each client implements a common interface while handling provider-specific requirements.

ai_sentinel.llm.BaseLLMClient(api_key, model)

Abstract Base Class for LLM Clients

ai_sentinel.llm.AzureOpenAIClient(api_key, ...)

Client implementation for Azure OpenAI LLM

ai_sentinel.llm.GeminiClient(api_key, model)

Client implementation for Google Gemini LLM

ai_sentinel.llm.OpenAIClient(base_url, model)

Client implementation for Open Source LLM using a local server that offers compatibility with the OpenAI SDK

Example Usage

See Also