[Phase 0.3.2] Create operator_use/guardrails/ module#40
Open
richard-devbot wants to merge 3 commits intoCursorTouch:mainfrom
Open
[Phase 0.3.2] Create operator_use/guardrails/ module#40richard-devbot wants to merge 3 commits intoCursorTouch:mainfrom
richard-devbot wants to merge 3 commits intoCursorTouch:mainfrom
Conversation
Adds the guardrails package with abstract base classes (Guardrail, ActionValidator, ContentFilter, PolicyEngine), concrete helpers (BlockListValidator, KeywordBlockFilter, RegexFilter, Composite*, RuleBasedPolicyEngine), GuardrailResult/RiskLevel value types, and a GuardrailRegistry for plugin-style registration and lookup. 57 unit tests in tests/security/test_guardrails_base.py — all passing.
b09ff65 to
2f0e06b
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 #12
What was implemented
Created the full
operator_use/guardrails/package from scratch:Base classes (
base.py)GuardrailResult— result object withaction(allow/block/confirm),reason,severity,metadata, and convenience factories.allow()/.block()/.confirm()RiskLevel—safe | review | dangerousGuardrailAction—allow | block | confirmGuardrail— abstract base withcheck(context) -> GuardrailResultActionValidator— abstract, requiresvalidate(tool_name, args, context)— pre-execution hookContentFilter— abstract, requiresfilter(content, context)— post-execution hookPolicyEngine— abstract, requiresclassify_risk(action)returningRiskLevelConcrete helpers
AllowAllValidator— passthrough (no-op default)BlockListValidator— deny-list of tool namesCompositeActionValidator— chains validators; BLOCK short-circuits, CONFIRM accumulatesPassthroughFilter— no-op content filterKeywordBlockFilter— case-insensitive phrase deny-listRegexFilter— compiled regex patternsCompositeContentFilter— chains filters with same BLOCK > CONFIRM > ALLOW precedenceRuleBasedPolicyEngine— dangerous/review tool-name listsCompositePolicyEngine— aggregates engines; DANGEROUS winsRegistry (
registry.py)GuardrailRegistry— register/unregister by name,get_all(type),get_enabled(type),run_all(type, context),clear()Tests
57 unit tests in
tests/security/test_guardrails_base.py— all passing.Coverage includes: factory methods, abstract enforcement, allow/block/confirm precedence in composite classes, disabled-guardrail skip, registry CRUD, type-filtered lookup, and
run_alldispatch.Ruff
ruff check— no issues.ruff format— 1 file auto-formatted.