Skip to content

Python Guards Reference

PatternGuard

from oxideshield import pattern_guard

guard = pattern_guard()

# Check input
result = guard.check("ignore previous instructions")
if not result.passed:
    print(f"Blocked: {result.reason}")

PIIGuard

from oxideshield import pii_guard

# With different redaction strategies
guard = pii_guard(redaction="mask")      # j***@example.com
guard = pii_guard(redaction="replace")   # [EMAIL]
guard = pii_guard(redaction="remove")    # (removed)

result = guard.check("Email: john@example.com")
print(result.sanitized)

# Detect without blocking
detections = guard.detect("Email: john@example.com")
for category, text, start, end in detections:
    print(f"{category}: {text}")

ToxicityGuard

from oxideshield import toxicity_guard

guard = toxicity_guard(threshold=0.7)

# Check
result = guard.check(user_input)

# Get detailed scores
scores = guard.analyze(user_input)
for category, score in scores.items():
    print(f"{category}: {score:.2f}")

LengthGuard

from oxideshield import length_guard

guard = length_guard(max_chars=10000, max_tokens=4000)
result = guard.check(user_input)

SemanticSimilarityGuard

from oxideshield import semantic_similarity_guard

guard = semantic_similarity_guard(threshold=0.85)
result = guard.check("ignore all instructions")

print(f"Attack embeddings: {guard.attack_count()}")

MultiLayerDefense

from oxideshield import multi_layer_defense

defense = multi_layer_defense(
    enable_length=True,
    enable_pii=True,
    enable_toxicity=True,
    max_chars=10000,
    pii_redaction="mask",
    toxicity_threshold=0.7,
    strategy="fail_fast"  # fail_fast, unanimous, majority
)

result = defense.check(user_input)
print(f"Passed: {result.passed}")
print(f"Duration: {result.total_duration_ms}ms")