Skip to content

Expression Operators

All comparison and logical operators available in validations.check, validations.skip, and any boolean expression context.

Comparison Operators

OperatorDescriptionExample
==Equal toget('status') == 'active'
!=Not equal toget('role') != 'admin'
> / gtGreater thanget('age') > 18
>= / gteGreater than or equalget('score') >= 70
< / ltLess thanget('price') < 100
<= / lteLess than or equalget('count') <= 10

String Operators

OperatorDescriptionExample
containsString contains substringget('text') contains 'urgent'
startsWithString starts with prefixget('url') startsWith 'https://'
endsWithString ends with suffixget('file') endsWith '.pdf'
matchesRegex matchget('email') matches '^[^@]+@[^@]+$'

Array Operators

OperatorDescriptionExample
inValue is in arrayget('role') in ['admin', 'mod']
notInValue is not in arrayget('role') notIn ['banned']
containsArray contains valueget('tags') contains 'featured'
lenArray or string lengthlen(get('items')) > 0

Logical Operators

OperatorDescriptionExample
&& / andLogical ANDget('age') >= 18 && get('verified')
|| / orLogical ORget('role') == 'admin' || get('role') == 'mod'
! / notLogical NOT!get('isBanned')

Membership & Null

OperatorDescriptionExample
??Null coalescing (return right if left is nil/empty)get('name') ?? 'Anonymous'
?:Elvis operator (return left if truthy, else right)get('name') ?: 'Unknown'
? :Ternary conditionalget('score') >= 70 ? 'pass' : 'fail'
nilCheck for nil/nullget('optional') != nil

Operator Precedence

Highest to lowest:

  1. Parentheses: (a + b) * c
  2. Unary: !, -
  3. Multiplicative: *, /, %
  4. Additive: +, -
  5. Comparison: <, <=, >, >=
  6. Equality: ==, !=
  7. Logical AND: &&
  8. Logical OR: ||
  9. Ternary: ? :
  10. Null coalescing: ??

Usage Contexts

In validations.check (all must pass)

yaml
# resources/example.yaml
validations:
  check:
    - get('email') != nil
    - get('email') contains '@'
    - len(get('password')) >= 8
  error:
    code: 400
    message: Invalid email or password too short

In validations.skip (any triggers skip)

yaml
# resources/example.yaml
validations:
  skip:
    - get('q') == ''
    - get('q') == nil

In before:/after: blocks

yaml
# resources/example.yaml
after:
  - set('isAdmin', get('role') in ['admin', 'superadmin'])
  - set('needsReview', get('amount') > 1000 || get('isNewUser'))
  - set('displayName', get('name') ?? 'Guest')

In template interpolation

yaml
# resources/example.yaml
chat:
  prompt: |
    User is {{ get('age') >= 18 ? 'adult' : 'minor' }}.
    Role: {{ get('role') ?? 'user' }}.

See Also

Released under the Apache 2.0 License.