Repository navigation
Guardrails & policy middleware (#892) - #1038
Merged
Merged
Conversation
Add a synapsekit.guardrails package: a Guard base with four enforcement modes (block/redact/flag/require_human), input guards (prompt-injection, jailbreak, topic allow/deny, max-cost), output guards (PII redaction, toxicity, citation-required, Pydantic schema), a GuardrailPolicy that composes and rolls them up (redact-mode hits chain), compliance rulepacks (HIPAA/GDPR/PCI), and a GuardedLLM wrapper over any BaseLLM. Every decision records a signed audit entry (self-reported GroundedSignal) and publishes a guardrail.* Live event carrying rule names/counts only, never the text. Pure-Python, no new deps, importable without extras.
Add 🛡️/🛑 icons and a story() branch so guardrail.check / guardrail.violation events render with stage, action, rule names, and violation count.
…#892) Cover injection/jailbreak blocking with a zero-false-positive benign set, per-guard behaviour and negatives, policy severity rollup and redaction chaining, signed audit chain (no raw text in payload), Live event emission (no raw text), bundle export, and the GuardedLLM wrapper block/redact paths.
AmitoVrito
force-pushed
the
feat/guardrails-middleware-892
branch
from
September 12, 2026 17:41
9e481ee to
650b4bb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #892.
Ships the v2.2.0 depth bet #892 — Guardrails & policy middleware: a unified, auditable I/O governance layer so LLM/agent I/O is validated, safe, and compliant by default. Composes primitives we already have (
MemoryPIIFilter, theaudithash-chain + Ed25519 signing,GroundedSignal, the LiveEventBus) into one policy surface.What's in it
Guardbase with four enforcement modes:block/redact/flag/require_human.inspect()is a coroutine, so LLM-backed guards fit the same contract.PromptInjectionGuard,JailbreakGuard,TopicGuard(allow/deny),MaxCostGuard.PIIRedactionGuard(reusesMemoryPIIFilter),ToxicityGuard,CitationRequiredGuard,SchemaGuard(Pydantic validation, no extra model call).GuardrailPolicy— composes guards over input/output stages, rolls findings into one report whose action is the most-severe triggered mode; redact-mode hits chain (rewriting text seen by later guards).GuardedLLM— wraps anyBaseLLM; blocks raiseGuardrailBlockedErrorbefore the model is called, output redaction rewrites the response, input redaction propagates into the wrapped call. No extra cache/retry layer of its own.hipaa_rulepack()/gdpr_rulepack()/pci_rulepack()(starter packs, not legal certification).guardrail.*SynapseKit Live event (🛡️/🛑) — both carry only guard names, counts, and the chosen action, never the inspected text.GuardrailPolicy.export_audit_bundle()writes an independently-verifiable bundle.Design notes
GuardedLLMis buffered so output redaction can see the whole response (documented).UNVERIFIABLEunless trusted keys are pinned — by design.Tests / gates (all green locally)
GuardedLLMblock/redact paths.inspect.iscoroutinefunction/isasyncgenfunctionasserts on the public surface.examples/guardrails_hipaa.py.Acceptance criteria (#892)
Guardrailmiddleware runnable on any LLM call (pre + post hooks)Follow-ups (not blocking): LLM-backed toxicity/grounding guards; token-incremental streaming redaction; agent/tool-call hooks beyond the LLM wrapper.