View a markdown version of this page

Condition operators - Amazon Bedrock AgentCore

Condition operators

A field test applies one or more condition operators to one field. This page describes the eight operators that version 1 of the record visibility configuration language supports. For each operator, it lists the fields it applies to and its operand, and shows how it matches present and absent values.

The following field test compares a record’s department label with two values.

"customMetadata/department": {"StringEquals": ["finance", "legal"]}

In this test, customMetadata/department is the field, StringEquals is the operator, and the list is the operand. For the fields that you can test and the values they hold, see Caller and record fields.

Reading field tests

A field test is a JSON object whose member names are operators, and it holds at least one operator. Version 1 accepts only the eight operator names on this page, spelled exactly as shown, with no aliases. Validation rejects any other name, so the service never ignores an unknown operator. It also never infers an operator from an operand’s shape.

The following rules apply to every field test:

  • Operators on one field combine with AND, and so do the field tests in a statement. A matching field test doesn’t grant or exclude anything by itself. For how tests and statements decide visibility, see Does a statement match? and Which statements decide visibility?.

  • A list operand means any of its values for StringEquals, StringEqualsIfExists, and ForAnyValue:StringEquals. It means none of its values for StringNotEquals, and all of them for ContainsAll. For the maximum list length, see Record visibility configuration limits.

  • String operators take JSON string literals, either alone or as list entries. StringEquals and StringEqualsIfExists also accept a caller-value reference, as described in Reference syntax and permitted positions. Validation rejects a number or Boolean literal instead of converting it. Caller numbers and Booleans compare in their string forms, so write "3", not 3, and "true", not true. For each value’s string form, see Supported caller values.

  • Comparisons are exact. For details, see Exact comparisons and author-supplied names.

The table in each operator section shows runtime results for a configuration that passed validation:

  • Match – The field test holds.

  • No match – The field test doesn’t hold.

In those tables, an absent attribute is a caller field that the caller doesn’t have. It also covers a value in a shape that the service doesn’t read, such as null or []. An absent label is a metadata field that the record’s approved revision has no value for. A missing referenced caller value works differently: the whole statement doesn’t apply to that caller, whatever the record’s label. For more information, see Missing referenced values.

Combining operators and choosing claim cardinality

A field test can hold several operators, and every one of them must hold. Each operator can appear only once in a field test, because a repeated member name is a duplicate key. To test several values with a string operator, use a list operand.

Validation checks every field test when you set the configuration. The following table lists the operators that one field test can combine on each kind of field.

Field Operators you can combine Restrictions

iam:accountId, iam:principalArn

StringEquals, StringNotEquals

These fields always have a value, so Exists is rejected.

iam:organizationId, iam:principalTag/<key>, and a jwt:claim/<name> tested as a single value

StringEquals, StringNotEquals, Exists

In an Allow statement, StringNotEquals requires "Exists": true, even beside StringEquals. In a Deny statement, StringNotEquals can appear without it.

A jwt:claim/<name> tested as a set, jwt:scopes, jwt:audiences

ForAnyValue:StringEquals, ContainsAll, Exists

None

recordType, name, recordId

StringEquals, StringNotEquals

These fields always have a value, so Exists is rejected.

A Text, Enum, or URL metadata field

StringEquals, StringNotEquals, Exists. Alternatively, StringEqualsIfExists alone.

Exists is optional beside StringNotEquals. StringEqualsIfExists can’t share its field test with another operator.

A Boolean metadata field

Bool, Exists. Alternatively, BoolIfExists alone.

BoolIfExists can’t share its field test with another operator.

Validation rejects an operator that the table doesn’t list for the field. For example, it rejects an IfExists operator on a caller field, a string operator on a Boolean metadata field, and Bool on a Text field. To require a caller attribute, use Exists.

A jwt:claim/<name> field can hold a single value or a set, and its operators decide how the configuration tests it. The scalar operators StringEquals and StringNotEquals test the claim as a single value. The set operators ForAnyValue:StringEquals and ContainsAll test it as a set. AWS Identity and Access Management (IAM) fields are always single values, and jwt:scopes and jwt:audiences are always sets.

A claim has one cardinality across the whole configuration, including statements with different effects. Validation rejects a configuration that tests one claim with both a scalar operator and a set operator. The error names both statements.

Exists and caller-value references don’t fix a claim’s cardinality. A scalar operator with a list operand still tests one value against alternatives, not set membership.

To choose a claim’s cardinality, check how your identity provider issues the claim:

  • If the claim can arrive as an array, even a one-element array, use set operators. A usable array is a set, and a scalar operator never matches it. An unsupported shape is absent and follows each operator’s absent row. A set operator reads a supported scalar as a one-element set, so it can test both shapes.

  • Use scalar operators only for a claim that your identity provider always issues as a single supported value: a string, number, or Boolean, which compare as strings.

For the values that each claim shape supplies, see Supported caller values.

Missing record labels

A record’s label is absent when its approved revision has no value for the metadata field. Declaring a field in the schema doesn’t give every record a label. Every record whose type’s schema doesn’t declare the field lacks it. So does a revision approved before the field was declared, and a revision that omits an optional field. For details, see customMetadata/<key>.

Some tests match records whose label is absent

A test can match records that you never labeled. Unguarded StringNotEquals, StringEqualsIfExists, and BoolIfExists match a record whose label is absent. In an Allow statement, such a test can grant unlabeled records, including every record of a type whose schema lacks the field. In a Deny statement, it hides them.

Positive tests (StringEquals, Bool, and Exists) don’t match an absent label. So a Deny statement that tests the label positively doesn’t hide an unlabeled record.

A match on an absent label isn’t a grant by itself. The record must be approved, and the caller’s request must be authorized. The statement’s other tests must match, and the statement must apply to the caller. A matching Deny statement still hides the record. For example, a Deny statement with a positive recordId or recordType test can hide an unlabeled record, because those fields always have a value.

Record and caller fields differ in one rule. On a metadata field, "Exists": true beside StringNotEquals is optional. Add it to keep the test from matching unlabeled records. On an optional caller field in an Allow statement, it’s required. So an Allow statement never grants through negation to a caller who lacks the attribute.

A missing referenced caller value is also different from a missing label. It makes the whole statement not apply, even with StringEqualsIfExists. For more information, see Missing referenced values.

To grant only records labeled with permitted values, list those values with StringEquals. Unlabeled records and newly introduced values then stay hidden unless another statement grants them. For the strict and permissive forms compared on the same records, see Unlabeled records and new values. Before you add or change a schema field, see Changing the schema.

StringEquals

StringEquals matches when the field’s single value equals the operand, or equals any string in an operand list. It applies to IAM caller fields, a JSON Web Token (JWT) claim tested as a single value, recordType, name, recordId, and Text, Enum, and URL metadata fields. It doesn’t apply to jwt:scopes, jwt:audiences, or Boolean metadata fields.

Its operand is a string or a nonempty list of strings. A literal for a field with a fixed format, such as recordId or iam:accountId, must use that format. You can combine StringEquals with StringNotEquals and Exists. For more information, see Combining operators and choosing claim cardinality.

The following fragment tests a caller’s department claim. The same results apply to the record test "customMetadata/department": {"StringEquals": "finance"}.

"jwt:claim/department": {"StringEquals": "finance"}

The following table shows the result for each value of the tested field.

Value of the tested field Field-test result

"finance"

Match

"legal" or "Finance"

No match

["finance"], a one-element array claim

No match

Attribute absent, or label absent

No match

A list operand, such as ["finance", "legal"], matches either value but still tests a single value. A claim that arrives as an array never matches. To test membership, use ForAnyValue:StringEquals.

An Allow statement with this test grants nothing to a caller who lacks the attribute, and doesn’t grant a record that lacks the label. A Deny statement with this test excludes neither that caller nor that record. Other statements still apply. For more information, see Which statements decide visibility?.

On a Text, Enum, or URL metadata field, the operand can instead be a caller-value reference, such as {"ref": "iam:principalTag/department"}. If the caller lacks the referenced value, the whole statement doesn’t apply. For more information, see Reference syntax and permitted positions.

StringNotEquals

StringNotEquals matches when the field is absent, or when its single value equals none of the operand strings. With a list operand, such as ["finance", "legal"], the value must differ from every listed string. It applies to the same fields as StringEquals. Its operand is a string or a nonempty list of strings, and it can’t be a caller-value reference.

StringNotEquals isn’t the opposite of StringEquals. A caller set, even a one-element array, matches neither of them. Absence also has different consequences for caller and record fields, so the following two tables show each side.

On an optional caller field, an Allow statement must pair StringNotEquals with "Exists": true. So the following caller fragment is valid only in a Deny statement. It’s meant to exclude every caller who isn’t an employee.

"jwt:claim/employment_type": {"StringNotEquals": "employee"}

The following table shows the result for each value of the caller’s claim.

Caller’s employment_type claim Field-test result

"contractor"

Match

"employee"

No match

["contractor"], a usable one-element array

No match

Attribute absent, including [] or an array that contains null or an object

Match

This Deny statement excludes callers who lack the claim or send it in an unsupported shape. It doesn’t exclude a caller who sends a usable array, so make sure that your identity provider issues the claim as a single string. With "Exists": true in the test, as an Allow statement requires, an absent attribute doesn’t match. To grant everyone except one department, including callers without the attribute, see Everyone except one department.

The following record fragment tests a Text metadata field. It’s valid in either effect.

"customMetadata/department": {"StringNotEquals": "finance"}

The following table shows the result for each stored label.

Stored department label Field-test result

"legal"

Match

"Finance"

Match, because comparisons are case-sensitive

"finance"

No match

Label absent

Match

In an Allow statement, this unguarded test grants records without the label. It also grants records with values that you haven’t listed yet, such as a new department. In a Deny statement, it hides those same records. To keep unlabeled records out of the test, add "Exists": true. To grant only permitted values, list them with StringEquals instead. For both forms, see Unlabeled records and new values.

StringEqualsIfExists

StringEqualsIfExists matches when a record has no label for the metadata field. It also matches when the label equals the operand or any string in an operand list. It applies only to Text, Enum, and URL metadata fields, not to caller fields or to recordType, name, and recordId. Its operand is the same as for StringEquals: a string, a nonempty list of strings, or a caller-value reference. It must be the only operator in its field test.

The following fragment assumes that the schema declares department as a Text field.

"customMetadata/department": {"StringEqualsIfExists": "finance"}

The following table shows the result for each stored label.

Stored department label Field-test result

"finance"

Match

"legal"

No match

Label absent

Match

The test matches every record without the label, including every record of a type whose schema doesn’t declare department. An Allow statement with it grants those records, and a Deny statement hides them. For more information, see Missing record labels.

With a caller-value reference as the operand, the test also matches records without the label. If the caller lacks the referenced value, the whole statement doesn’t apply, as described in Missing referenced values.

Bool

Bool matches when a Boolean metadata field’s stored value equals the operand. It applies only to Boolean metadata fields, and its operand must be the JSON value true or false. Quoted Booleans aren’t valid operands. You can combine Bool with Exists. For more information, see Combining operators and choosing claim cardinality. To test a Boolean JWT claim, use a string operator with "true" or "false". For the string forms, see Supported caller values.

The following field-test fragment assumes that the schema declares restricted as a Boolean field.

"customMetadata/restricted": {"Bool": true}

The following table shows the result for each stored value.

Stored restricted value Field-test result

true

Match

false

No match

Label absent

No match

A Deny statement with this test doesn’t hide a record that lacks the label. To match missing labels as well, use BoolIfExists. A field match contributes to the statement’s decision only when its other tests match. For more information, see Which statements decide visibility?.

BoolIfExists

BoolIfExists matches when a record has no label for a Boolean metadata field, or when the stored value equals the operand. It applies only to Boolean metadata fields, not to caller fields. Its operand must be the JSON value true or false, not a quoted Boolean, and it must be the only operator in its field test.

The following fragment assumes that the schema declares restricted as a Boolean field.

"customMetadata/restricted": {"BoolIfExists": true}

The following table shows the result for each stored value.

Stored restricted value Field-test result

true

Match

false

No match

Label absent

Match

The test matches every record without the label, including every record of a type whose schema doesn’t declare restricted. So a Deny statement with this test hides unlabeled records along with records labeled true, and an Allow statement grants both. For more information, see Missing record labels. For a Deny statement that hides restricted records from every grant, see Hide restricted records from every grant.

ForAnyValue:StringEquals

ForAnyValue:StringEquals matches when at least one caller value equals one of the operand values. It applies to JWT claims tested as sets, jwt:scopes, and jwt:audiences. It doesn’t apply to IAM or record fields. Its operand is a string or a nonempty list of strings.

The following principal-test fragment requires membership in either group.

"jwt:claim/groups": {"ForAnyValue:StringEquals": ["finance-readers", "finance-ops"]}

The following table shows the result for each shape of the caller’s claim.

Validated groups claim Field-test result

"finance-readers" (scalar)

Match

["finance-readers"] (one-element array)

Match

["auditors", "finance-ops"]

Match

["auditors"]

No match

Attribute absent, including null, [], or an unsupported shape

No match

You can combine this operator with ContainsAll or Exists. Across the configuration, the same claim can’t also use StringEquals or StringNotEquals. For more information, see Combining operators and choosing claim cardinality. For supported shapes, see Supported caller values.

An Allow statement with this test grants nothing to a caller whose attribute is absent. A Deny statement with it excludes nothing from that caller, so a broad Allow statement still grants records to that caller. To exclude callers without the claim as well, require it with Exists in the Allow statement instead of a "*" principal. For this pattern, see Everyone except members of a group.

ContainsAll

ContainsAll matches when the caller’s set contains every value in the operand list. The set can also hold values that you didn’t list, in any order. It applies to JWT claims tested as sets, jwt:scopes, and jwt:audiences. It doesn’t apply to IAM or record fields. Its operand must be a nonempty list of strings, not a single string or a caller-value reference.

The following principal-test fragment requires both groups.

"jwt:claim/groups": {"ContainsAll": ["finance", "reader"]}

The following table shows the result for each shape of the caller’s claim.

Validated groups claim Field-test result

["finance", "reader"]

Match

["reader", "ops", "finance"]

Match

["finance"]

No match, because reader is missing

"finance" (scalar, read as a one-element set)

No match

Attribute absent, including null, [], or an unsupported shape

No match

An Allow statement with this test grants nothing to a caller whose attribute is absent. A Deny statement with it excludes nothing from that caller.

No operator restricts a caller’s set to only the values in a list. Values that you didn’t list never prevent a match with ContainsAll or ForAnyValue:StringEquals.

You can combine ContainsAll with ForAnyValue:StringEquals or Exists on the same claim. The claim then can’t use StringEquals or StringNotEquals anywhere in the configuration. For a test that requires one group plus any of several others, see Require membership in all listed groups.

Exists

Exists matches when the field has a value. It applies to every declared metadata field, including Boolean fields, and to the caller fields that can be absent. Those are iam:organizationId, iam:principalTag/<key>, jwt:claim/<name>, jwt:scopes, and jwt:audiences. It doesn’t apply to iam:accountId, iam:principalArn, recordType, name, or recordId, which always have a value.

Its operand must be the JSON value true. No operator tests for absence alone, so "Exists": false is rejected. Exists can stand alone, or share a field test with the scalar, set, or Bool operators that the field allows. It can’t share a field test with an IfExists operator. For more information, see Combining operators and choosing claim cardinality.

The following fragment requires a department label. The same results apply to {"Exists": true} on any field that Exists applies to, including a caller field.

"customMetadata/department": {"Exists": true}

The following table shows the result for each kind of value.

Value of the tested field Field-test result

A string, including an empty string, ""

Match

A Boolean label, including false

Match

A caller set, including a one-element array

Match

Attribute absent, including null, [], an object, an unsupported array, or a scope string that is empty or holds only spaces (U+0020)

No match

Label absent

No match

Beside StringNotEquals, Exists keeps the negation from matching an absent value. It’s required on an optional caller field in an Allow statement, and optional on a metadata field. For how that choice affects unlabeled records, see Missing record labels.