Annotators
Annotators handle the detection logic Cedar cannot express: regular expressions, substring and suffix checks, numeric comparisons, and lengths. Each PolicyAnnotator derives named values from the raw request before any rule runs. Rules read the values as context.annotations.<name>, and effects can copy them into headers or finding labels.
A First Example
This annotator flags credential-shaped text and labels its kind:
A rule can now write when { context.annotations.secret_detected }, and an effect can set a header from context.annotations.secret_kind.
Annotation Outputs
Guard every string and integer annotation with has before you read it in Cedar:
Fields
Each rule reads one field of the request.
A field that does not exist in the request never matches.
Operations
Patterns use the syntax of the Rust regex crate, which is similar to RE2. Lookaround and backreferences are not supported.
Producing Integers
Use an integer annotation to expose a number to Cedar, for example the length of a message:
Load-Time Checks
The evaluator rejects an annotator, and with it the whole policy, when:
- An annotation has no rules.
- A rule is missing its operation’s operand, or its pattern does not compile.
- An operation does not fit the output type, such as
lengthon aboolannotation. - A
stringannotation’s rule has novalue. - A field selector is not one of the supported forms.
- Two annotations anywhere in the bundle share a name.
Writing Good Detectors
- Keep detection and decision separate. An annotator should say what it saw, and a rule should decide what to do about it.
- Use a
boolannotation withset_true_if: anyfor a detection flag, and astringannotation withset_value_from: first_matchfor its classification. List the same patterns in both, in the same order. - Every annotation runs on every request APF evaluates. Keep patterns specific.
- The repository’s demo bundle includes
annotators/secret-detector.yamlandannotators/pii-detector.yamlas starting points.
Next Steps
- To act on these signals, refer to Content Controls.
- To copy annotation values into headers and findings, refer to Effects and Findings.