Skip to main content

Equitas: AI Safety & Observability Platform

Project description

Equitas: AI Safety & Observability Platform

Enterprise-grade AI safety wrapper for LLM applications

Equitas is a comprehensive AI safety platform that wraps around OpenAI (and other LLM) APIs to provide real-time toxicity detection, bias checking, hallucination detection, jailbreak prevention, and compliance monitoring. Built for enterprises who need to ensure their AI applications are safe, unbiased, and compliant.

Key Features

  • Multi-Layer Safety Detection - Toxicity, bias, hallucination, and jailbreak detection
  • Custom ML Models - No vendor lock-in, uses open-source transformer models
  • Credit-Based System - Flexible usage-based billing and credit management
  • Real-Time Analytics - Comprehensive dashboard with metrics and incident tracking
  • Enterprise Ready - Multi-tenant architecture with data isolation
  • Easy Integration - Drop-in replacement for OpenAI API

Quick Start

Installation

pip install equitas

Basic Usage

from equitas_sdk import Equitas, SafetyConfig

# Initialize client
client = Equitas(
    openai_api_key="sk-your-openai-key",
    equitas_api_key="your-equitas-key",
    tenant_id="your-org-id",
    backend_api_url="http://localhost:8000",  # Optional
)

# Make safe API calls
response = await client.chat.completions.create_async(
    model="gpt-4",
    messages=[{"role": "user", "content": "Hello!"}],
    safety_config=SafetyConfig(
        on_flag="auto-correct",  # strict | auto-correct | warn-only
        enable_hallucination_check=True,
    )
)

# Access safety metadata
print(f"Toxicity Score: {response.safety_scores.toxicity_score}")
print(f"Hallucination Score: {response.safety_scores.hallucination_score}")
print(f"Bias Flags: {response.safety_scores.bias_flags}")
print(f"Jailbreak Detected: {response.safety_scores.jailbreak_flag}")

Architecture

┌─────────────────┐
│  Your App       │
│  + Equitas SDK  │
└────────┬────────┘
         │
         └──────────────► Equitas Backend API
                          ├── Custom Toxicity Detection
                          ├── Bias Detection
                          ├── Jailbreak Prevention
                          ├── Hallucination Detection
                          └── Credit Management
                          
                          ↓
                      
                     Database (Logs, Metrics, Credits)
                     
                          ↓
                          
                     Dashboard & Analytics

Safety Features

1. Custom Toxicity Detection

  • Model: Uses unitary/toxic-bert (RoBERTa-based)
  • No OpenAI Dependency: Fully independent, no vendor lock-in
  • Categories: Detects toxic, severe toxic, obscene, threat, insult, identity hate
  • Cost: 1 credit per analysis

2. Hallucination Detection

  • Multi-Component: Semantic consistency, contradiction detection, factuality checking
  • Pattern Analysis: Detects overconfident language and unsupported claims
  • Context Aware: Can verify against knowledge base
  • Cost: 3 credits per analysis

3. Advanced Jailbreak Detection

  • Pattern Matching: Detects known jailbreak patterns
  • Semantic Analysis: Catches paraphrased attempts
  • Behavioral Detection: Identifies suspicious indicators
  • Adversarial Detection: Catches encoding tricks
  • Cost: 1.5 credits per analysis

4. Enhanced Bias Detection

  • Stereotype Association: Detects stereotype reinforcement
  • Demographic Parity: Tests fairness across demographics
  • Fairness Metrics: Statistical parity and equalized odds
  • Intersectional Analysis: Detects compounding bias
  • Cost: 2 credits per analysis

5. Credit Management System

  • Balance Tracking: Real-time credit balance monitoring
  • Transaction History: Full audit trail
  • Usage-Based Billing: Pay only for what you use
  • Flexible Plans: Add credits as needed

Project Structure

equitas/
├── equitas_sdk/          # Client SDK
│   ├── client.py         # Main SDK client
│   ├── models.py         # Data models
│   └── exceptions.py    # Custom exceptions
│
├── backend_api/          # Backend API
│   ├── main.py          # FastAPI application
│   ├── api/v1/          # API endpoints
│   │   ├── analysis.py  # Safety analysis endpoints
│   │   ├── credits.py   # Credit management
│   │   ├── metrics.py   # Analytics
│   │   └── incidents.py # Incident tracking
│   ├── services/        # ML services
│   │   ├── custom_toxicity.py
│   │   ├── hallucination.py
│   │   ├── advanced_jailbreak.py
│   │   └── enhanced_bias.py
│   └── models/          # Database models
│
└── examples/            # Usage examples

Setup & Configuration

1. Install Dependencies

pip install equitas

2. Start Backend API

# Option 1: Direct run
python -m backend_api.main

# Option 2: Using uvicorn
uvicorn backend_api.main:app --reload --port 8000

Backend will be available at http://localhost:8000

3. Configure Environment

Create .env file:

# OpenAI (for LLM calls)
OPENAI_API_KEY=sk-your-key-here

# Database
DATABASE_URL=sqlite+aiosqlite:///.equitas.db

# Security
SECRET_KEY=your-secret-key-change-in-production

4. Add Credits to Tenant

import httpx

# Add credits via API
response = httpx.post(
    "http://localhost:8000/v1/credits/add",
    headers={
        "Authorization": "Bearer your-api-key",
        "X-Tenant-ID": "your-tenant-id",
    },
    json={
        "amount": 1000.0,
        "description": "Initial credits",
    }
)

API Endpoints

Safety Analysis

POST /v1/analysis/toxicity

Analyze text for toxicity using custom ML models.

{
  "text": "Text to analyze",
  "tenant_id": "org123"
}

POST /v1/analysis/bias

Check for demographic bias.

{
  "prompt": "Original prompt",
  "response": "LLM response",
  "tenant_id": "org123"
}

POST /v1/analysis/jailbreak

Detect jailbreak attempts.

{
  "text": "Text to check",
  "tenant_id": "org123"
}

POST /v1/analysis/hallucination

Detect hallucinations in responses.

{
  "prompt": "Original prompt",
  "response": "LLM response",
  "tenant_id": "org123",
  "context": ["fact1", "fact2"]  // Optional
}

Credit Management

GET /v1/credits/balance

Get current credit balance.

POST /v1/credits/add

Add credits to account.

{
  "amount": 1000.0,
  "description": "Monthly subscription",
  "reference_type": "subscription"
}

GET /v1/credits/transactions

Get transaction history with pagination.

POST /v1/credits/calculate-cost

Calculate cost before executing operations.

{
  "operation_types": ["toxicity", "bias", "jailbreak"]
}

Analytics & Metrics

GET /v1/metrics

Get aggregated metrics (usage, safety scores, incidents).

GET /v1/incidents

Query flagged incidents with filters.

Credit System

Credit Costs

Operation Cost (Credits)
Toxicity Detection 1.0
Bias Detection 2.0
Jailbreak Detection 1.5
Hallucination Detection 3.0
Remediation 2.0
Full Analysis 7.5

Handling Insufficient Credits

from equitas_sdk.exceptions import InsufficientCreditsException

try:
    response = await client.chat.completions.create_async(...)
except InsufficientCreditsException as e:
    print(f"Insufficient credits!")
    print(f"Required: {e.required}")
    print(f"Available: {e.available}")
    # Handle error - prompt user to add credits

Testing

Run Dataset Tests

# Test all components
python tests/run_dataset_tests.py

# Test specific component
python tests/run_dataset_tests.py toxicity datasets/toxicity/test.csv

See tests/DATASET_TESTING_GUIDE.md for details.

Safety Configuration

SafetyConfig(
    on_flag="auto-correct",  # strict | auto-correct | warn-only
    toxicity_threshold=0.7,
    enable_bias_check=True,
    enable_jailbreak_check=True,
    enable_hallucination_check=True,
    enable_remediation=True,
)

Action Modes

  • strict: Raises exception on safety violation
  • auto-correct: Automatically remediates unsafe content
  • warn-only: Returns warnings but allows content

Deployment

Docker

docker build -t equitas .
docker run -p 8000:8000 --env-file .env equitas

Production Considerations

  • Use PostgreSQL instead of SQLite
  • Configure proper CORS origins
  • Set up Redis for caching
  • Enable rate limiting
  • Use GPU for faster ML inference
  • Set up monitoring and alerting

Documentation

What Makes Equitas Stand Out

  1. No Vendor Lock-In - Custom ML models, no dependency on external APIs
  2. Comprehensive - Covers toxicity, bias, hallucination, jailbreak, and more
  3. Enterprise Ready - Multi-tenant, credit system, audit trails
  4. Explainable - Detailed explanations for every safety flag
  5. Production Ready - Low latency, scalable, battle-tested
  6. Easy Integration - Drop-in replacement for OpenAI API

Contributing

Contributions welcome! Please see CONTRIBUTING.md for guidelines.

License

MIT License - see LICENSE file

Support


Built for AI Safety

Start protecting your AI applications today with Equitas.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

equitas-2.0.1.tar.gz (501.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

equitas-2.0.1-py3-none-any.whl (59.7 kB view details)

Uploaded Python 3

File details

Details for the file equitas-2.0.1.tar.gz.

File metadata

  • Download URL: equitas-2.0.1.tar.gz
  • Upload date:
  • Size: 501.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for equitas-2.0.1.tar.gz
Algorithm Hash digest
SHA256 ef7a5d99824fcbbb9be0c1ae087a7e7fd352bad37b22f27c2bd17f25bbf32c65
MD5 44b9e9b9c859623ee9278b823f39432b
BLAKE2b-256 c380dcb69172a57f96af8b3e38770d3e45bbe1187700dd9d5ab7337ba098f1c0

See more details on using hashes here.

File details

Details for the file equitas-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: equitas-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 59.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for equitas-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 525d0efe22a04913cc78233fdcdb21b67f46890ac07a581ffd3afc635c6e99ca
MD5 d4612c9cc6519a37ceef6a728815e09c
BLAKE2b-256 eb76af8e1aed099ec9cf63a1fe576e1b4558f9cdf1732ba2997d7b86f379b5f9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page