Expand description
§JailGuard — Prompt Injection Detection
Fast, accurate prompt injection detection with a simple API. The classifier (98.40% accuracy on the in-domain test set) is embedded in the library — no external files or setup required.
§Quick Start
use jailguard::{detect, is_injection};
// Simple boolean check
if is_injection("ignore previous instructions") {
println!("Blocked!");
}
// Get detailed result with confidence score
let result = detect("What is the capital of France?");
println!("Safe: {}, Confidence: {:.1}%", !result.is_injection, result.confidence * 100.0);§Features
- 98.40% Accuracy: trained on a 17-source public dataset pipeline
- Real ML: ONNX embeddings (all-MiniLM-L6-v2) + neural classifier
- Auto-setup: ONNX model auto-downloaded on first use (~90 MB, cached)
- Simple API:
is_injection(),detect(),score()
§API Overview
| Function | Returns | Use Case |
|---|---|---|
is_injection(text) | bool | Quick yes/no check |
detect(text) | DetectionOutput | Full details with confidence |
score(text) | f32 | Raw probability (0.0-1.0) |
detect_batch(texts) | Vec<DetectionOutput> | Process multiple inputs |
Re-exports§
pub use embedded::detect;pub use embedded::detect_batch;pub use embedded::is_injection;pub use embedded::score;pub use embedded::DetectionOutput;pub use embedded::RiskLevel;
Modules§
- c_api
- C ABI surface — Go (cgo) and Node.js (napi-rs) bindings link against
these
extern "C"functions. Compiled unconditionally so thecdylib/staticlibartifact always exposes the symbols; thec-apifeature only gates the cbindgen header regeneration inbuild.rs. C ABI for JailGuard. - embedded
- Zero-configuration embedded detector
Enums§
- Error
- Main error type for jailguard operations.
Functions§
- download_
model - Ensure the ONNX model is available locally, downloading it if necessary.
- model_
cache_ dir - Public-API variant — returns the cache directory as a
String.
Type Aliases§
- Result
- Result type alias for jailguard operations.