Returning a Decision with Its Reason

A structured decision can carry both the outcome and a reason a caller can use for display, logging, or a follow-up action.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Choose a stable reason
  2. Test similar visible outputs
  3. Represent supporting facts separately from the verdict
  4. Test which observations remain valid over time

Choose a stable reason

A reservation decision may return denied with reason sold out or outside window. Keep the reason in a stable code if another part of the program branches on it. The interface can format messages separately under parsing and formatting.

Test similar visible outputs

Use one expired booking and one full session. Both may display “Unavailable” in a compact list. Their reason codes should still differ if the next step is different. This is a postcondition that callers can verify without parsing prose.[1][2]

Represent supporting facts separately from the verdict

A loan-period rule in a library may allow renewal when no hold exists and the renewal count is below two. For a book held by another reader after one renewal, a result can carry allowed=False and a stable reason code for the hold. When both conditions fail, decide whether a single reason takes priority or all applicable reasons appear. Give the display layer the facts needed to explain the decision. See decision tables.

Test which observations remain valid over time

If the rules later add a reason, code branching on a stable verdict can still work without relying on a specific text message. For a persistent audit, keep the input facts or a version of the rule so a past verdict can be understood under the rule applied at the time. Test a permitted case, a single failing condition and a combined failure. See record equality to decide which fields identify equivalent results.

References

  1. Python Software Foundation, Python Tutorial: Control Flow ↩
  2. Python Software Foundation, Python Language Reference: Execution Model ↩