Detecte/docs

Operators reference

Detecte's policy expression language is a subset of MongoDB's query language. Expressions live inside the when clause and evaluate against the action context.

Context shape

{
  action: string,                       // the action name
  params: Record<string, unknown>,      // action parameters
  context: Record<string, unknown>,     // free-form metadata
  agent: { id, name, tier, risk_score }
}

You can refer to nested fields with dot syntax: "params.amount", "agent.tier", "context.user.role".

Comparison

OperatorMeaningExample
$eqequal{ "agent.tier": { $eq: "high" } }
$nenot equal{ action: { $ne: "ping" } }
$gt, $gtegreater than{ "params.amount": { $gt: 1000 } }
$lt, $lteless than{ "params.amount": { $lte: 5 } }
$inin list{ "params.country": { $in: ["US","CA"] } }
$ninnot in list{ "params.country": { $nin: ["XX"] } }
$regexmatches regex{ "context.email": { $regex: "@acme\\.com$" } }
$existsfield present{ "params.recipient": { $exists: true } }

Logical

{
  "$and": [
    { "action": "transfer" },
    { "params.amount": { "$gt": 10000 } },
    { "$or": [
      { "context.region": "US" },
      { "context.region": "EU" }
    ]}
  ]
}

$and, $or, and $not compose normally. The implicit operator on a top-level object is $and.

Time

OperatorMeaning
$hourBetween: [start, end]UTC hour falls between (inclusive). Wraps midnight.
$dayOfWeek: { $in: [0,6] }0 = Sunday.

Strict-equality shortcut

A bare scalar means $eq:

{ "action": "refund_order" }

is equivalent to

{ "action": { "$eq": "refund_order" } }