← Workflow lessons

2. Apply a policy to the flow

An Open Policy Contract (OPC) defines when an action can proceed and which facts the decision uses. Link the policy to the workflow or step it governs. The host supplies facts from trusted sources, such as the caller’s permissions and the current record state. The engine evaluates the rule before invoking the protected operation.

A rule that permits an update only when the caller has permission and the record is open might use this CEL expression.

context.canUpdate && context.recordIsOpen

To report a refusal, give the OBC a decision step before the write and declare separate routes for permission and refusal. The write keeps its policy check. The policy supplies the decision, and the OBC decides where it leads.

Follow a permitted request

The caller has permission and the record is open. The policy permits the update. The engine calls the save operation and takes the next transition from its result.

Follow a refused request

The caller has permission and the record is closed. The policy blocks the save. The declared refusal route returns an explanation and the record keeps its existing value.