The Guardian SDK is the definitive framework for building, testing, and deploying custom governance modules within the HardRAG ecosystem. Optimized for Sovereign and Cloud-Native workloads.
🏗️ Core Architecture
The SDK leverages DSPy for programmatic prompt optimization and Pydantic for structured validation. Every Guardian module follows a strict "Consensus Intelligence" signature.
1. Defining a Custom Guardrail
To build a specialized auditor (e.g., Legal Document PII or Banking Transaction Audit), inherit from the base HardRAGModule.
from app.hardrag.modules import HardRAGGuard
import dspy
class FinancialComplianceGuard(dspy.Module):
"""
Audits financial instructions against internal AML/KYC policies.
"""
def __init__(self):
super().__init__()
self.auditor = dspy.ChainOfThought("prompt, policy -> verdict, rationale")
def forward(self, prompt, policy):
# The 'Sovereign Consensus' logic
result = self.auditor(prompt=prompt, policy=policy)
return dspy.Prediction(verdict=result.verdict, rationale=result.rationale)
2. Integration with HardRAG Guard
Once your module is defined, register it with the HardRAGGuard orchestrator to enable multi-agent consensus.
from app.hardrag.guard import HardRAGGuard
# Initialize the Sovereign Guard
guard = HardRAGGuard()
# Add your custom Guardian module
guard.register_module(
id="aml_auditor",
module=FinancialComplianceGuard(),
tier="PLATFORM"
)
🌀 Continuous Self-Improvement
Guardian SDK modules are natively compatible with the HardRAG Feedback Loop.
- Training: Captured audit logs are automatically used as "Few-Shot" examples.
- Optimization: Use
optimizer.run(module)to refine prompt weights based on CISO-corrected history.
🔒 Security & Performance
- Zero-Knowledge Logs: All training data is sanitized before entering the optimization loop.
- Cryptographic Audit Integrity: Modules registered at the PLATFORM tier automatically receive a
SHA-256-SIGNEDintegrity seal in the audit feed. - Latency Target: Optimal Guardian modules should maintain an overhead of < 150ms.
🚀 Deployment (Sovereign Mode)
To deploy your custom guardrails in an air-gapped environment:
- Compile your DSPy program to
optimized_weights.json. - Map the weights directory to the Sovereign Vault container.
- HardRAG will detect the custom signatures and activate the Certified Trace.
[!TIP] Developer Support: For partners, the HardRAG engineering team provides technical support for complex module development.
