How Do I Model Validation?

Model validation as named rules and explicit outcomes. Avoid hiding business validation in prose or implying that invalid input simply becomes a generic error.

Use Rules For Conditions

A rule names a condition that matters to the capability. In this example, one rule prevents self-approval and another limits the requested duration.

Use Outcomes For Meaningful Rejections

Each failed validation path maps to a distinct outcome in the when block. That makes validation behaviour visible to readers, tests, diagrams, and future tooling.

leave-request.dcl
language dcl 0.9

actor Employee is human
actor Manager is human

shape LeaveRequestInput {
  employeeId: Uuid required
  daysRequested: Number required
}

capability RequestLeave {
  intent LeaveRequestInput from Employee

  actors {
    requester: Employee
    approver: Manager
  }

  outcomes {
    LeaveRequested
    SelfApprovalRejected
    DurationRejected
  }

  rules {
    ApproverIsDifferent:
      actors.requester is not equal to actors.approver

    DurationWithinLimit:
      input.daysRequested is less than 21
  }

  when {
    ApproverIsDifferent violated then SelfApprovalRejected
    DurationWithinLimit violated then DurationRejected
    otherwise then LeaveRequested
  }
}

Open in Playground