API Reference
Crate: oxide-guard-sdk
Re-exported Types
From oxideshield-guard:
- Guard — Core guard trait
- GuardAction — Action enum (Allow, Block, Sanitize, Log, Alert, Suggest)
- GuardCheckResult — Result of guard evaluation
- GuardError — Guard error type
- GuardResult<T> — Result alias
From oxideshield-core:
- Severity — Severity levels (Info, Low, Medium, High, Critical)
- Match — Match with position, pattern, severity, metadata
- Pattern — Pattern definition (literal or regex)
- PatternMatcher — Multi-strategy pattern matcher
From oxide-guard-derive:
- Guard (derive macro) — Auto-implement Guard trait
Module: builder
GuardBuilder
| Method |
Signature |
Description |
new |
fn new(name: impl Into<String>) -> Self |
Create builder |
add_keyword |
fn add_keyword(self, kw: impl Into<String>) -> Self |
Add keyword |
add_keywords |
fn add_keywords(self, kws: impl IntoIterator<Item = impl Into<String>>) -> Self |
Add multiple keywords |
add_pattern |
fn add_pattern(self, p: impl Into<String>) -> Self |
Alias for add_keyword |
set_severity |
fn set_severity(self, s: Severity) -> Self |
Set match severity |
set_action |
fn set_action(self, a: GuardAction) -> Self |
Set action |
case_insensitive |
fn case_insensitive(self, ci: bool) -> Self |
Set case sensitivity |
set_threshold |
fn set_threshold(self, t: f32) -> Self |
Set confidence threshold |
build |
fn build(self) -> Result<KeywordGuard, GuardError> |
Build the guard |
Module: templates
RegexGuard
| Method |
Description |
new(name, action) |
Create guard |
add_pattern(regex) -> Result<Self, regex::Error> |
Add regex pattern |
add_patterns(&[regex]) -> Result<Self, regex::Error> |
Add multiple patterns |
with_severity(severity) |
Set match severity |
KeywordGuard
| Method |
Description |
new(name, keywords, threshold, action, severity, case_insensitive) |
Create guard |
CustomMLGuard
| Method |
Description |
new(name, predict_fn) |
Create with prediction function |
with_threshold(f32) |
Set score threshold (default 0.5) |
with_action(action) |
Set action |
with_model_path(path) |
Set model file path |
model_path() |
Get model path |
ApiGuard (feature: api)
| Method |
Description |
new(name, endpoint) |
Create with API endpoint |
with_action(action) |
Set action |
with_timeout(duration) |
Set request timeout |
with_api_key(key) |
Set API key |
CompositeGuard
| Method |
Description |
new(name) |
Create composite guard |
add_guard(Box<dyn Guard>) |
Add child guard |
with_strategy(strategy) |
Set aggregation strategy |
with_action(action) |
Set composite action |
CompositeStrategy
| Variant |
Description |
FailAny |
Fail if any child fails (default) |
FailAll |
Fail only if all children fail |
For advanced voting strategies (majority, weighted), see OxideShield Pro's EnsembleGuard.
Module: utils
| Function |
Signature |
Description |
tokenize |
fn(text: &str) -> Vec<String> |
Split on whitespace/punctuation, lowercase |
normalize |
fn(text: &str) -> String |
Lowercase, trim, collapse spaces |
pattern_match |
fn(text: &str, pattern: &str) -> bool |
Case-insensitive substring/glob match |
similarity |
fn(text1: &str, text2: &str) -> f32 |
Jaccard similarity on token sets |
Module: prelude
Imports everything commonly needed:
use oxide_guard_sdk::prelude::*;
// Brings in: Guard, GuardAction, GuardCheckResult, GuardError, GuardResult,
// Severity, Match, Pattern, PatternMatcher,
// GuardBuilder, RegexGuard, KeywordGuard, CustomMLGuard, CompositeGuard,
// ApiGuard (with api feature), utils, Guard derive macro
Python API
CustomGuard
| Method |
Description |
__init__(name, action="block") |
Create guard |
pass_check() |
Return passing result |
flag(reason, matches=None) |
Return failing result |
create_match(text, start, end, category) |
Create match object (static) |
check(text) |
Override in subclass |
get_name() |
Get guard name |