Raxe
The main synchronous client for threat detection.Constructor
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | str | None | None | API key. If None, reads from config or env |
config_path | Path | None | None | Custom config file path |
telemetry | bool | True | Enable privacy-preserving telemetry |
l2_enabled | bool | True | Enable L2 ML detection |
voting_preset | str | None | None | L2 voting strategy preset: “balanced”, “high_security”, “low_fp” |
progress_callback | object | None | None | Optional progress indicator for initialization |
scan()
Scan a single prompt for threats.| Parameter | Type | Default | Description |
|---|---|---|---|
text | str | required | Text to scan |
tenant_id | str | None | None | Tenant ID for multi-tenant policy resolution |
app_id | str | None | None | App ID within tenant for policy resolution |
policy_id | str | None | None | Override policy for this scan only |
customer_id | str | None | None | Customer identifier for tracking |
context | dict | None | None | Additional context metadata |
block_on_threat | bool | False | Raise SecurityException on threat |
mode | str | "balanced" | Performance mode: “fast”, “balanced”, “thorough” |
l1_enabled | bool | True | Enable L1 rule detection |
l2_enabled | bool | True | Enable L2 ML detection |
confidence_threshold | float | 0.5 | Minimum confidence for detections |
explain | bool | False | Include detailed explanations |
dry_run | bool | False | Skip tracking and history (for testing) |
use_async | bool | True | Use async pipeline for parallel L1+L2 (5x speedup) |
suppress | list | None | None | Rule patterns to suppress |
ScanPipelineResult
Raises:
ValidationError: If text is empty or invalidSecurityException: Ifblock_on_threat=Trueand threat detected
scan_fast()
Fast scan using L1 rules only (< 3ms).scan(text, l2_enabled=False, mode="fast").
scan_thorough()
Thorough scan with all layers (< 100ms).scan(text, mode="accurate").
protect
Decorator for automatic function protection.| Parameter | Type | Default | Description |
|---|---|---|---|
block | bool | True | Raise exception on threat |
on_threat | callable | None | None | Custom threat handler |
allow_severity | list | None | None | Severities to allow through |
suppressed()
Context manager for scoped suppressions.| Parameter | Type | Description |
|---|---|---|
*patterns | str | Rule patterns to suppress |
action | str | Action: “SUPPRESS”, “FLAG”, “LOG” |
reason | str | Reason for suppression (required) |
Context Manager
Use as context manager for proper resource cleanup:AsyncRaxe
Async client for high-throughput scenarios.Constructor
| Parameter | Type | Default | Description |
|---|---|---|---|
cache_size | int | 1000 | Max cached scan results |
cache_ttl | float | 300.0 | Cache TTL in seconds |
scan()
Async scan of a single prompt.scan_batch()
Async batch scanning with concurrency control.| Parameter | Type | Default | Description |
|---|---|---|---|
texts | list[str] | required | List of texts to scan |
max_concurrency | int | 10 | Max concurrent scans |
use_cache | bool | True | Use result cache |
Cache Management
close()
Explicitly close the client and flush telemetry.Context Manager
Recommended usage:Properties
BothRaxe and AsyncRaxe expose these properties:
| Property | Type | Description |
|---|---|---|
usage_tracker | UsageTracker | Usage statistics tracker |
scan_history | ScanHistoryDB | Local scan history database |
stats | dict | Preload statistics |
Thread Safety
Raxeis thread-safe for concurrent scansAsyncRaxeis safe for concurrent async tasks- Both clients maintain internal state safely
