Use rules.When to apply a subset of rules only when a specific condition is met. Conditions are evaluated based on the object's state, as rules do not have access to context.Context.
To ensure faults land on the correct field when a requirement is conditional, combine is.Not with rules.When.
// Apply rules for 'stamps' only if the envelope is not signed
rules.When(is.Func("not signed", envelopeNotSigned),
rules.Field("stamps",
rules.Assert("12", "stamps not allowed before signing", is.Length(0, 0)),
),
)