AI AI-02.04
Expert systems and rule engines
Knowledge base plus inference engine, the MYCIN story, why expert systems were brittle, and where explicit rules still win today.
The big idea
In the 1970s and 1980s, the most commercially successful kind of AI was not a learning system. It was the expert systemA program that captures a specialist's knowledge as if-then rules and uses an inference engine to reach conclusions and explain them.: a program that captured what a specialist knows as hundreds or thousands of if-then rules, and applied them to a new case the way the specialist would. Ask it about a patient, a loan or a computer order, and it would give an answer and, unlike most modern models, explain exactly which rules led there.
Think of a very thorough checklist written by your most experienced colleague. "If the customer is new and the order is unusually large, check their ID. If the ID check fails, stop." A junior employee following it makes the same decisions the expert would, at least for the cases the expert thought of. That last clause is the whole story of expert systems: superb inside the situations their authors imagined, and helpless just outside them.
How it works
Step 1: Separate the knowledge from the engine
The key design decision was to keep what the system knows apart from how it reasons:
- The knowledge baseThe part of an expert system that stores the domain knowledge, usually as if-then rules, separately from the program that applies them. holds the rules, written by a knowledge engineer who interviews the human experts.
- The working memory holds the facts about the current case: the patient's symptoms, the order's items.
- The inference engineThe program that applies the rules in the knowledge base to the facts of a case, by forward or backward chaining, to derive conclusions. applies rules to facts, by forward or backward chaining, to reach conclusions.
- An explanation facility can answer "why are you asking this?" and "how did you conclude that?" by showing the chain of rules.
Separating the two meant the same engine could be reused for a new domain by writing a new rule base, and the rules could be read and corrected by the experts themselves.
Step 2: The MYCIN story
MYCIN, built at Stanford in the 1970s, is the best-known early expert system. It helped choose treatment for serious bacterial infections of the blood: which organism was probably responsible, and which antibiotic to give. Its knowledge was a few hundred rules of the form "if the infection is of this type and the organism has these properties, then there is suggestive evidence that it is that organism".
MYCIN introduced two ideas that shaped the field. It reasoned backward from goals ("which organism is it?") and so asked the doctor only for the facts it needed, one question at a time. And because medical evidence is rarely certain, each rule carried a certainty factor, a number expressing how strongly the evidence supported the conclusion, which MYCIN combined as rules fired. In published evaluations its treatment recommendations compared well with those of infectious-disease specialists. Yet it was never used in routine practice: entering each case took a long time, it lived outside the hospital's workflow, and questions of responsibility for a machine's advice were unresolved.
Step 3: The boom and the bust
In the 1980s, companies built expert systems for computer configuration, equipment diagnosis, credit decisions and much more. A well-known example, XCON at Digital Equipment Corporation, checked and completed customer orders for complex computer systems using forward-chaining rules, and grew to thousands of rules. By the late 1980s, though, the field ran into hard limits, the market for specialised AI hardware collapsed, and funding dried up: part of the second "AI winter" ( A short history of AI ).
Try it
Here is a miniature rule engine for card payments, with forward chaining and an explanation of which rules fired:
# A tiny forward-chaining rule engine for card payments.
# Each rule: name, condition on the facts, facts it adds.
RULES = [
("new-device", lambda f: f["device_days"] < 1, {"risk:device"}),
("far-away", lambda f: f["km_away"] > 500, {"risk:location"}),
("big-amount", lambda f: f["amount"] > 1000, {"risk:amount"}),
("night", lambda f: f["hour"] < 5, {"risk:time"}),
("two-risks", lambda f: len(risks(f)) >= 2, {"review"}),
("three-risks", lambda f: len(risks(f)) >= 3, {"block"}),
]
def risks(f):
return {x for x in f["derived"] if x.startswith("risk:")}
def run(facts):
facts, why = {**facts, "derived": set()}, []
changed = True
while changed: # forward chaining to a fixed point
changed = False
for name, cond, adds in RULES:
new = adds - facts["derived"]
if new and cond(facts):
facts["derived"] |= new
why.append(name)
changed = True
d = facts["derived"]
verdict = "BLOCK" if "block" in d else "REVIEW" if "review" in d \
else "ALLOW"
return verdict, why
CASES = {
"groceries": dict(amount=62, km_away=3, device_days=400, hour=18),
"new phone": dict(amount=1500, km_away=2, device_days=0, hour=14),
"stolen card": dict(amount=1800, km_away=900, device_days=0, hour=3),
# dozens of tiny online payments a minute: no rule looks at frequency
"card testing": dict(amount=1, km_away=0, device_days=900, hour=15),
}
for name, facts in CASES.items():
verdict, why = run(facts)
print(f"{name:12} {verdict:6} rules fired: {', '.join(why) or 'none'}")Output
groceries ALLOW rules fired: none
new phone REVIEW rules fired: new-device, big-amount, two-risks
stolen card BLOCK rules fired: new-device, far-away, big-amount, night, two-risks, three-risks
card testing ALLOW rules fired: none The first three cases work beautifully, and every decision comes with its reasons, which a bank needs when a customer asks why their card was blocked. The fourth is the problem. A fraudster testing stolen card numbers with dozens of tiny online payments triggers nothing, because no rule looks at how often payments happen. The rules are not wrong; they are incomplete, and they cannot notice that.
Now decide where rules are the right tool:
Going deeper
Why expert systems were brittle
- Narrow competence, no common sense. A system knew its domain and nothing else. Ask a medical system about a case with a typing error in the patient's age, and it would reason confidently about a patient aged 450.
- No graceful degradation. Just outside its rules, quality did not drop slowly; it fell off a cliff, often without any warning.
- The knowledge acquisition bottleneck. Experts know more than they can say. Extracting rules took months of interviews and still missed cases.
- Maintenance. With thousands of interacting rules, adding one could change behaviour far away. Large rule bases became hard to understand even for their own authors.
- No learning. The world changed and the rules did not, unless a person rewrote them.
Machine learning attacked exactly these weaknesses by inducing patterns from data. It brought its own problems, chiefly that learned knowledge is hard to inspect and explain.
Where rules still win
Explicit rules are still the right tool when decisions must be exact, explainable and controllable: regulatory compliance, tax and benefits calculations, insurance eligibility, pricing policies, and access control. Banks run fraud rule engines next to machine-learning models: the model produces a risk score, and rules turn scores and hard facts into decisions ("block if score is above 0.9 or the merchant is on a sanctions list"). Rules can be changed in minutes when a new attack appears, while retraining takes longer.
Modern business rules engines, such as the open-source Drools, descend directly from expert-system shells. They use Rete-style matching algorithms to check thousands of rules against changing facts efficiently, and they let analysts edit rules in decision tables without touching code.
Rules around language models
The pattern returns with language models. A model drafts an answer; explicit rules check it ("never quote a price that is not in the catalogue", "refunds over a limit need a human"). This keeps the flexible part flexible and the critical part exact, the same division of labour as a fraud model plus a rule engine.
Trade-offs
| Option | Wins when | Loses when |
|---|---|---|
| Expert system / rule engine | Explicit, auditable decisions where the logic is known and must be exact | Brittle outside its rules; costly to build and maintain at scale; cannot learn |
| Learned model | Fuzzy patterns, shifting data, perception and language | Hard to explain or guarantee; needs data and monitoring |
| Model plus rules | High-stakes decisions that need both pattern-finding and hard constraints | Two systems to build, test and keep consistent |
Common mistakes
- Assuming a rule base is complete because it handles every test case. Real inputs include cases nobody imagined.
- Letting a rule base grow without tests and owners. Every rule should have a reason, an author and a test.
- Replacing a working, auditable rule set with a model just because models are newer. If the logic is known and stable, rules are cheaper and clearer.
- Hard-coding thresholds that should be learned, such as what counts as an unusual amount for each customer.
In the wild
Where you will see this: banks and payment companies run rule engines alongside fraud models; insurers and governments encode eligibility and benefit rules; e-commerce platforms express pricing and promotion policies as rules; and business rules management systems are used in large companies to let analysts change decision logic safely. Medical software still uses rule-based alerts, such as warnings about dangerous drug interactions.
Check yourself
-
What are the two main parts of an expert system?
Show answer
B. A knowledge base of rules and an inference engine Keeping the domain rules separate from the reasoning engine let the same engine serve many domains and let experts read the rules.
-
Why did MYCIN attach certainty factors to its rules?
Show answer
B. Because medical evidence is rarely conclusive, so conclusions needed a degree of belief Each rule's certainty factor expressed how strongly evidence supported a conclusion, combined as rules fired.
-
In the code sample, why does the card-testing case get through?
Show answer
B. No rule looks at payment frequency, so no rule fires Rule systems only know the situations their authors anticipated. The rules were correct but incomplete.
-
Which task is the best fit for explicit rules?
Show answer
C. Applying a legally defined eligibility checklist The logic is known, must be applied exactly, and must be explainable, which is where rules excel.
Recap
- Expert systems store specialist knowledge as if-then rules and apply it with an inference engine that can explain itself.
- MYCIN reasoned backward with certainty factors and matched specialists in evaluations, but never entered routine use.
- They were brittle: narrow, unable to learn, costly to build and hard to maintain at scale.
- Rule engines still win where decisions must be exact, auditable and quickly changeable, often next to a learned model.