Rules Writing Pitfalls to Avoid
After many requests, I am starting a best practices series on rules authoring. Today, I’m going to focus on rules writing pitfalls that can complicate decision management.
Surprisingly, there is very little literature out there to help business analysts design the best business rules. My goal is document the wisdom that I have collected over the past 20 years in the decision management industry. Regardless what product you use to write rules, the syntax can be tricky. Initially, I considered removing problematic constructs from our SMARTS™ decision management platform. However, some cases benefit from them. Therefore, we left them in… with the warning that you should use them only when necessary. That being said, here’s what rules writing pitfalls to avoid:
Pitfall #1: OR
A rule typically consists of a set of conditions connected through AND or OR. For example, an auto insurer might check whether an applicant is a student and/or is under 21 years old. In other words:
- Version 1: Applicant is a student AND applicant is less that 21 years old.
- Version 2: Applicant is a student OR applicant is less than 21 years old.
Since there are only 2 conditions, both version are clear.
OR is Ambiguous
However, using OR with multiple conditions gets confusing fast. For example, let’s see what happens when there are 3 conditions: Applicant is a student OR applicant is less than 21 years old AND applicant resides in California.
This statement is ambiguous and could be interpreted in two ways:
- Interpretation 1: (Applicant is a student OR applicant is less than 21 years old) AND applicant resides in California.
- Interpretation 2: Applicant is a student OR (applicant is less than 21 years old AND applicant resides in California).
A 25-year old student from Vermont would fail the check under the first interpretation but pass under the second. As you can see, with OR, the order of operations matters. Each rules engine has its default order but that order may not be the same across all engines.
OR Prevents Business Performance Tracking
In addition, OR makes it difficult to track business performance. Rules engines can report on how many times a condition fires (is met). However, OR bundles conditions together, making it unclear which conditions are met. For example, if a report indicates that “Applicant is a student OR applicant is less than 21 years old” fired 5 times. You do not know how many of the 5 met the student condition versus the age condition. The following would all lead that condition to fire 5 times:
- Applications from 5 students of various ages
- Applications from 5 non-students, all under 21
- Applications from 3 students of various ages and applications from 2 non-students who under 21
Altogether, I strongly recommend you avoid OR and only use AND. So why do we have OR in the first place? I think it’s a historical artifact from Expert Systems. I acknowledge that there certain cases (ex. complex rules that only look for a few alternatives) for which OR could be useful. That being said, when in doubt, avoid OR.
But, wait! Don’t OR and AND mean different things? I can’t just swap them out! Majority of the time, you can replace OR by using IN. For example, “Applicant residency is IN (California, Vermont)” is preferable to “Applicant resides in California OR applicant resides in Vermont.” I talk more about OR in business rules here.
Pitfall #2: ELSE
Historically, rules can include an ELSE statement. ELSE specifies what actions to take when the set of conditions is not met. Again, this makes sense in English. However, with rules, ELSE increases the likelihood that you will apply actions to scenarios that you did not intend.
For example, let’s say an auto insurer that operates in California, Oregon, and Washington has different eligibility rules for every state. In California, and applicant has to be at least 17 years old to be eligible. A business analyst comes up with the following rule:
- IF Applicant resides in California
- AND applicant is at least 17 years old
- THEN applicant is eligible
- ELSE applicant is ineligible
The business analyst wants every applicant that resides in California who is under 17 to be ineligible. However, how the rule is written, every applicant that resides in Oregon and Washington will be ineligible. Typically the work around for ELSE involves adding rules that negate other rules. This is neither easy to write nor easy to maintain.
There are a few use cases in which the condition set is black & white. When it is true, something happens; when it is not true, something else happens.
In the majority of the use cases, you have more than just one rule that defines the behavior the rules look for. In that case, you are likely considering having an ‘ELSE’ statement that is global to the rule set. I have seen rule sets that needed that complex negation of all of the exceptions identified by the rules. This is not fun to write and maintain.
Therefore, like with OR, I strongly recommend you avoid ELSE. Instead, I recommend the following:
Default Actions
If your rules engine supports default actions, use them. A default action is a “global” rule set that applies when none of the conditions are met. With default actions, a business analyst could come up with the following:
- Rule #1: IF Applicant resides in California AND applicant is at least 17 years old THEN applicant is eligible
- Rule #2: IF Applicant resides in (Oregon, Washington) AND applicant is at least 20 years old THEN applicant is eligible
- Default action: Applicant is ineligible
Referencing Changes
If your rules engine doesn’t support default actions, use can derive them through a 2-step process. Every rule that fires will lead to some change (action), likely a status modification and/or a log entry. For example, let’s say every application record in your database has an application_status field which starts out as empty (unknown). When an applicant is considered eligible, you populate “eligible” in the application_status field. And when an applicant is considered ineligible, you populate “ineligible” in the application_status field. You can leverage these changes to set your default action.
- First, execute the rules that are the exceptions to your desired default action. For example, execute Rule #1 and Rule #2 from above. Applications that meet the conditions in either Rule #1 and Rule #2 will now have “eligible” in their application_status.
- Second, create and execute rules derived from the status changes to carry out your default action. For example, the rule might be IF application status is unknown, THEN applicant is ineligible. Now, any application that was run through the first set of rules and has an empty application_status will now be changed to “ineligible.”
Pitfall #3: PRIORITIES
In general, rules will execute in the order that they appear. This is great because what you see if what you get. The exception is when you leverage the RETE algorithm, which executes on inference. Priorities, another historical artifact, allow a rule to jump ahead of all the other rules and execute first. This may be useful when you’re using RETE. However, in most cases, you don’t need to. Adding priorities changes the execution order which may cause confusion to the next business analyst that’s reviewing the decision project. Therefore, like with OR and ELSE, I strongly recommend you avoid using priorities.
Instead, simply reorder the rules in the order that you would like them to execute. As a pro tip, decompose complex decisions into steps that a person can easily review. For example, a product recommendation decision can be broken down into the following steps:
- First, execute rules that identify all products an applicant is eligible for.
- Second, execute rules that scores the eligible products based on company profitability and/or likelihood of applicant acceptance.
- Third, execute rules that selects the best product to recommend to the applicant.
From Rules Writing Pitfalls to Peaks
As Nicolas Boileau-Despreaux said, “What is conceived well is expressed clearly, and the words to say it will arrive with ease.” Avoid the rules writing pitfalls I covered, and instead, focus on expressing your rules clearly and concisely. This way, your rules will be much easier to maintain and manage.
Continue reading my Rules Authoring Best Practices series:
- Making Decisions or Not?
- Decision Design
- Release Management
- QA Testing
- Decisions in Production
- Business Testing
- Object Model First
- Rules Requirements 101
- Data-Centric Approach to Rules Authoring
- Rules for Data Validation
Learn more about Decision Management and Sparkling Logic’s SMARTS™ Data-Powered Decision Manager

