CEL engine
Look up how DefenseClaw runs CEL rules: the evaluation pipeline, what a rule pack must pass to load, the supported CEL subset, resource limits and results.
DefenseClaw uses CEL as a bounded matcher, not a general policy language. The gateway turns a tool call into typed ActionFacts and runs one Boolean expression per rule. How to write a rule: Custom rules with CEL.
Evaluation pipeline
Each rule is checked on its own. CEL runs only on calls the parser understood in full. A match is checked a second time against only the commands that will really run.
List view for small screens. Use the expand button to open the drawing.
- Parses the argumentsinto ActionFacts
- checksFully understood?
- Fully understood?nothing unsupportedor ambiguous
- yesCEL matches?
- noRegex pattern runs
- CEL matches?on the full facts
- error, over budgetRegex pattern runs
- falseNo finding
- trueMatches what really runs?
- Regex pattern runsinstead of CEL
- raw matchDetection only
- No findingregex fallback skipped
- Matches what really runs?execute-only view
- yesEnforcement candidate
- noDetection only
- Detection onlyrecorded, action unchanged
- Enforcement candidateto the final proof check
Text version of this diagram
- Parses the arguments: into ActionFacts (gateway)
- checks to Fully understood?
- Fully understood?: nothing unsupported, or ambiguous (decision)
- yes to CEL matches?
- no to Regex pattern runs
- CEL matches?: on the full facts (decision)
- error, over budget to Regex pattern runs
- false to No finding
- true to Matches what really runs?
- Regex pattern runs: instead of CEL (policy layer)
- raw match to Detection only
- No finding: regex fallback skipped (component)
- Matches what really runs?: execute-only view (decision)
- yes to Enforcement candidate
- no to Detection only
- Detection only: recorded, action unchanged (component)
- Enforcement candidate: to the final proof check (component)
Every finding, from CEL or a fallback, then passes one final check: it can change the action only with a complete proof pinned to the same rule ID, on a connector that can block. The check never removes a finding. A built-in rule marked alert-only can raise at most alert.
ActionFacts and raw tool arguments stay inside the gateway. They are not exposed through an endpoint, logged as CEL input or written to the state ledger.
Loading a rule pack
The loader compiles every expression, disabled rules included. Each must be Boolean, have no surrounding whitespace and use only the subset below, and its rule must have a valid pattern fallback.
- A custom category with a new name adds rules.
- A category with the name of a shipped category replaces that whole category.
- Any schema, regex, type, enum or cost failure rejects the whole pack. A gateway that already runs a pack keeps it.
Supported CEL subset
| Supported | Examples and constraints |
|---|---|
| Boolean logic | &&, ||, ! |
| Scalar comparison | ==, !=, and in for Boolean, integer and string values |
| Collection predicates | exists and all comprehensions; nesting is limited to two levels. A comprehension must give a Boolean, so validate-pack refuses map, filter and exists_one (semantic_surface) |
| String predicates | startsWith, endsWith, contains, and member-form matches |
| Literals | Boolean, integer, string and scalar lists |
| Field selection | Typed fields reachable from f, in snake case |
Refused: arithmetic, ordering comparisons, indexing, ternaries, maps, has, null, float, unsigned and byte literals, other functions, and message or list equality. There are no custom helper functions. matches takes a literal RE2 pattern of at most 512 bytes; dynamic patterns and matches(value, pattern) are refused.
Resource limits
| Limit | Maximum |
|---|---|
| Expression size | 16 KiB |
| Checked syntax tree | 4,096 nodes; depth 64 |
| Comprehension nesting | 2 |
| CEL regex literal | 512 bytes |
| Fallback regex | 2,048 bytes |
| Static cost per rule | 6,000,000 |
| Runtime cost per rule | 1,250,000 |
| CEL rules per pack | 256 |
| Static cost of all enabled rules | 32,000,000 |
| Total cost per tool call | 24,000,000 (a cost bound, not a time limit) |
A pack over a load limit is refused. A rule over a runtime limit falls back to its regex; other rules keep running.
The 512-byte CEL regex limit caps its size; the static cost limit can reject a shorter pattern. Check the whole rule with defenseclaw guardrail validate-pack. Its refusal messages:
| Problem | Message |
|---|---|
| Nesting too deep | it nests exists() and all() too deeply; flatten the check or split it into separate rules |
| Over the static cost | estimated worst-case evaluation cost is above the per-rule limit. Test one list, prefer ==, in or startsWith over contains or matches in a nested comprehension, or split the rule. |
Runtime results
| Result | What happens |
|---|---|
| The pack fails to compile or load | It is not used. |
| The call was not parsed in full | The rule's regex fallback runs; a match is detection-only. |
CEL returns false | No finding from this rule. |
| CEL matches all facts but not the execute-only view | Detection only: a preview cannot block. |
| CEL matches both on a connector that can block | Enforcement candidate, subject to the final proof check. |
| CEL matches on a connector that cannot block | Detection only. |
| CEL errors, times out or runs over cost | The regex fallback runs; other rules continue. |
Some partly parsed commands are still read in full for CEL:
- A redirect target expanded at run time (
> "$HOME/out.txt"): the command is analyzed with a stand-in target. A match counts when the expression does not depend on the redirect or path. &&and||lists (cd dir && cmd): a block stops the whole call, so each list is judged as if every command runs. A rule that blocksa; balso blocksa && b.- A PowerShell list that is partial because of one statement: statements are read in order up to the first that cannot be proved.
A fallback match and a CEL match never produce two findings for the same rule. Custom rules own their own rule ID.
Single calls and chains
A CEL rule matches one call. The 26 ordered chains are a fixed, built-in list; a rule pack cannot add one. Only authenticated connector hook events with a session and invocation ID can advance a chain. Inspect, proxy and telemetry traffic never do. The chain list is on Deterministic detection, and which connector events count is on Tool-call state.
Test engine behavior
defenseclaw guardrail validate-pack checks schema, regex, CEL typing and cost. It does not inject facts or prove that a connector supplies the fields an expression reads, so test a match and a near miss on each connector in observe mode.
Custom rules with CEL
Add your own guardrail rule to a copy of a rule pack with a CEL expression over a tool call's parsed facts and a regex fallback, then validate and test it.
Decision model
An optional fast model that answers allow, confirm or block for tool calls, in front of the LLM judge or on its own. Off by default.