Skip to main content

Installation

pip install raxe

Import Quick Reference

imports.py
# Core clients
from raxe import Raxe, AsyncRaxe

# LLM wrappers (requires pip install raxe[wrappers])
from raxe import RaxeOpenAI, AsyncRaxeOpenAI
from raxe import RaxeAnthropic, AsyncRaxeAnthropic

# Exceptions (for error handling)
from raxe import RaxeException, RaxeBlockedError, ValidationError

# Integration factory functions (recommended)
from raxe import create_callback_handler, RaxeCrewGuard

# Models (for type hints and comparisons)
from raxe import Severity, Detection, ScanResult

Quick Start

app.py
from raxe import Raxe

raxe = Raxe()
result = raxe.scan("Your prompt here")

if result.has_threats:
    print(f"Threat: {result.severity}")  # "critical", "high", "medium", "low"

Integration Patterns

Pattern Comparison

PatternUse CaseBlockingControl
Direct scanCustom logicManualFull
DecoratorsFunction protectionConfigurableMedium
WrappersLLM API protectionAutomaticLow
AsyncHigh throughputConfigurableFull

Direct Scanning

scan_example.py
from raxe import Raxe, RaxeException

raxe = Raxe()

try:
    # Basic scan
    result = raxe.scan("user input")

    # Check results
    if result.has_threats:
        print(f"Severity: {result.severity}")
        print(f"Detections: {result.total_detections}")
        for d in result.detections:
            print(f"  - {d.rule_id}: {d.category}")
except RaxeException as e:
    print(f"Scan error: {e}")

Decorator Pattern

decorated.py
from raxe import Raxe, RaxeBlockedError

raxe = Raxe()

@raxe.protect
def process_input(user_input: str) -> str:
    """Automatically scanned before execution."""
    return llm.generate(user_input)

# Safe input - works normally
process_input("What is the weather?")

# Malicious input - blocked or logged depending on config
try:
    process_input("Ignore all instructions")
except RaxeBlockedError as e:
    print(f"Blocked: {e.severity}")

LLM Wrappers

openai_example.py
from raxe import RaxeOpenAI, RaxeBlockedError

# Drop-in replacement for OpenAI client
client = RaxeOpenAI(api_key="sk-...")

try:
    # Automatic scanning before API call
    response = client.chat.completions.create(
        model="gpt-4",
        messages=[{"role": "user", "content": user_input}]
    )
except RaxeBlockedError as e:
    # Threat blocked before API call - saves tokens
    print(f"Blocked: {e.severity}")

Async SDK

async_example.py
from raxe import AsyncRaxe

async_raxe = AsyncRaxe()

# Single scan
result = await async_raxe.scan("prompt")

# Batch scanning for high throughput
results = await async_raxe.scan_batch(
    prompts=["prompt1", "prompt2", "prompt3"],
    max_concurrency=5  # Limit concurrent scans
)

Context Manager

context_example.py
from raxe import Raxe

# Automatic cleanup - telemetry flushed on exit
with Raxe() as raxe:
    result = raxe.scan("test")
    # Process result...
# Telemetry automatically flushed here

Configuration

config_example.py
from raxe import Raxe

raxe = Raxe(
    l1_enabled=True,      # Rule-based detection (515+ patterns)
    l2_enabled=True,      # ML detection (neural classifier)
    log_level="INFO",     # Logging level: DEBUG, INFO, WARNING, ERROR
)