Skip to main content

assert

assert is a DCL operation that checks document state without mutating it.

Use it as a guardrail before later operations. If the assertion fails, execution stops.

YOp

- assert:
path: config/database/host
exists: true
type: scalar

Parameters

ParameterTypeRequiredDescription
pathstringyesPath to check.
equalsanynoExpected value for a deep equality check.
existsbooleannotrue requires the path to exist. false requires it to be absent.
typestringnoExpected value type. Allowed values are mapping, sequence, and scalar.

At least one of equals, exists, or type must be provided.

Behavior

  • Reads the document without changing it.
  • All provided conditions must pass.
  • Fails fast with ASSERTION_FAILED if a condition is not met.
  • Can check values, existence, types, sequence indexes, and match paths.

Errors

ErrorMeaning
ASSERTION_FAILEDA declared condition was not met.
INVALID_OPNo assertion condition was provided.

Example

yops:
- assert:
path: config/database/host
exists: true
type: scalar

Input:

config:
database:
host: localhost

Output:

config:
database:
host: localhost