Repository navigation
Conversation
Slice 1 of HEN-139: guard rules with assignments and audit, checks through decision models or structured chat output, GuardMiddleware ahead of provider routing (guard_blocked on enforced block rules), prompt-free guard events and an admin test endpoint that runs the same evaluation without acting on it.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
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.
Slice 1 of HEN-139 (Guardrails). This is the first PR of a stack: UI, test suite, reroute and gateway checks build on it.
What it does
Prompts are checked against admin-defined rules before they reach a model.
guard_rules,guard_rule_assignments(everyone, team, user or key) andguard_events, all in the initial schema. Also theadmin.guard.view|edit|test|events.viewpermissions and en/de translations.src/types/guard/classifier.rs): the check model's type picks the strategy. Decision models get a predicate, or a choice over the policy's categories plusnone. Chat models answer with a strict JSON schema (matched,category,confidence,reason). The prompt is sent apart from the instructions, which tell the model to treat it as data only. Checks are billed to the user asguard, or to the admin asguard_test.evaluate.rs): rules run in parallel, each with its own timeout. Any trigger at or above its threshold makes the rule match. Block beats log-only, then priority decides. Monitor rules never act, and new rules start in monitor mode. Block rules fail closed by default.GuardMiddlewareis registered inbuild_enginebeforeProviderRoutingMiddleware. An enforced block answersguard_blocked(403) with the rule's message or a default, plus the reason unless the rule hides it.guard,guard_testandtitlerequests are skipped, and tool steps aren't checked again./api/v1/admin/guard:rules(CRUD, update isPUTwith the whole rule),rules/{id}/assignments, andPOST test, which runsallrules for a simulated subject, chosenidsor an unsaveddraft.Still planned for this PR
if_true/if_false.ProviderKind::SystemOnecomes in a separate provider PR outside this stack.fit_prompt, which cuts long prompts, with checks over up to 8 chunks where the worst score wins. Anything larger counts as a failed check, so the rule'son_errordecides.Not in this slice
GET /events, cost per event and a rate limit on/test(slice 2)Tests
src/tests/guard.rs: conflict resolution, monitor mode,on_error, timeouts, verdict parsing, prompt selection, validation and prompt fitting all pass locally. The two DB tests (rule selection per subject, and the middleware blocking end to end with events that hold no prompt text) haven't run locally because Docker isn't running; CI runs them.