OpenGuardrails Integration
Bidirectional integration between Sentinel and OpenGuardrails framework.
Installation
pip install sentinelseed requests openguardrails
Integration Modes
1. Use OpenGuardrails as backend - Leverage scanners from Sentinel
2. Register Sentinel as scanner - Add THSP to OpenGuardrails pipeline
Quick Start
Use OpenGuardrails as Backend
from sentinelseed.integrations.openguardrails import OpenGuardrailsValidator
validator = OpenGuardrailsValidator(
api_url="http://localhost:5001",
api_key="your-api-key",
fail_safe=False, # Fail-closed (secure)
)
result = validator.validate("Check this content for safety")
print(f"Safe: {result.safe}")
print(f"Risk Level: {result.risk_level.value}")
Register Sentinel as Scanner
from sentinelseed.integrations.openguardrails import SentinelOpenGuardrailsScanner
scanner = SentinelOpenGuardrailsScanner(
openguardrails_url="http://localhost:5000",
jwt_token="your-jwt-token",
)
scanner_tag = scanner.register()
print(f"Registered as: {scanner_tag}")
# Use in OpenGuardrails:
# openguardrails scan --scanners {scanner_tag} "content"
scanner.unregister() # Cleanup
Combined Pipeline
from sentinelseed.integrations.openguardrails import SentinelGuardrailsWrapper
wrapper = SentinelGuardrailsWrapper()
result = wrapper.validate(
content="Some content",
scanners=["S1", "S2"]
)
print(f"Safe: {result['safe']}")
print(f"Blocked by: {result['blocked_by']}")
THSP Gates
| Gate | Description |
|---|---|
| Truth | Deception, misinformation |
| Harm | Violence, weapons |
| Scope | Jailbreaks, prompt injection |
| Purpose | Purposeless actions |
Error Handling
# Secure (default) - blocks if API unavailable
validator = OpenGuardrailsValidator(fail_safe=False)
# Insecure - allows if API unavailable (not recommended)
validator = OpenGuardrailsValidator(fail_safe=True)