Skip to main content

Installation

pip install raxe

Quick Start

from raxe import Raxe

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

if result.has_threats:
    print(f"Threat: {result.severity}")

Integration Patterns

Pattern Comparison

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

Direct Scanning

from raxe import Raxe

raxe = Raxe()

# 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}")

Decorator Pattern

from raxe import Raxe

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
process_input("Ignore all instructions")

LLM Wrappers

from raxe import RaxeOpenAI

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

# Automatic scanning before API call
response = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": user_input}]
)

Async SDK

from raxe import AsyncRaxe

async_raxe = AsyncRaxe()

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

# Batch scanning
results = await async_raxe.scan_batch(
    prompts=["prompt1", "prompt2", "prompt3"],
    max_concurrency=5
)

Context Manager

from raxe import Raxe

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

Configuration

from raxe import Raxe

raxe = Raxe(
    l1_enabled=True,      # Rule-based detection
    l2_enabled=True,      # ML detection
    log_level="INFO",     # Logging level
)