Expert Systems in AI

Last Updated 17 Aug, 2026
Quick Answer

What is an expert system in AI?

An expert system is an AI program that captures human expert knowledge as IF-THEN rules to solve problems and make decisions in a specific domain. It separates domain knowledge from the reasoning engine, making rules transparent and easy to update.

  • Core components: Knowledge Base and Inference Engine
  • Differences between forward chaining and backward chaining
  • How to build a simple forward-chaining system in Python

An expert system is a program that captures the know-how of a human expert as a set of rules, then uses those rules to answer questions or make decisions in that expert's field.

What Is an Expert System?

An expert system solves problems in a narrow domain the same way a human specialist would — by applying stored expert knowledge to the specific facts of a situation. Instead of one block of code with the logic baked in, the knowledge and the reasoning are kept separate, which makes the rules easy to inspect, explain, and update.

Components of an Expert System

Every expert system is built from three core parts.

Knowledge Base

The knowledge base stores everything the system knows about the domain — facts and IF-THEN rules written by capturing a human expert's knowledge, like IF has_fever AND has_cough THEN suspect_flu.

Inference Engine

The inference engine is the reasoning part. It takes the facts it's given, checks them against the rules in the knowledge base, and works out what new facts or conclusions follow.

How Expert Systems Make Decisions

The inference engine reaches a conclusion by chaining rules together, in one of two directions.

  • Forward chaining starts with known facts and fires any rule whose conditions are met, adding new facts until nothing more can be concluded.
  • Backward chaining starts with a goal (like "does the patient have the flu?") and works backward, checking what facts would be needed to prove it.

Example: A Simple Forward-Chaining Expert System 

This toy system uses forward chaining to reach a diagnosis from a small set of starting facts. It's a simplified illustration of the mechanism, not real medical guidance.

rules = [
    (["has_fever", "has_cough"], "suspect_flu"),
    (["suspect_flu", "has_bodyache"], "diagnosis_flu"),
    (["has_fever", "has_rash"], "suspect_measles"),
    (["suspect_measles", "has_watery_eyes"], "diagnosis_measles"),
]
def forward_chain(known_facts):
    facts = set(known_facts)
    changed = True
    fired = []
    while changed:
        changed = False
        for conditions, conclusion in rules:
            if all(c in facts for c in conditions) and conclusion not in facts:
                facts.add(conclusion)
                fired.append((conditions, conclusion))
                changed = True
    return facts, fired
known_facts = ["has_fever", "has_cough", "has_bodyache"]
facts, fired = forward_chain(known_facts)
print("Starting facts:", known_facts)
print()
print("Rules fired:")
for conditions, conclusion in fired:
    print(f"  IF {' AND '.join(conditions)} THEN {conclusion}")
print()
print("Final facts:", sorted(facts))

Output

Starting facts: ['has_fever', 'has_cough', 'has_bodyache']
Rules fired:
  IF has_fever AND has_cough THEN suspect_flu
  IF suspect_flu AND has_bodyache THEN diagnosis_flu
Final facts: ['diagnosis_flu', 'has_bodyache', 'has_cough', 'has_fever', 'suspect_flu']

Explanation:

The first rule fires because both has_fever and has_cough are already known, adding suspect_flu. That new fact then satisfies the second rule's conditions along with has_bodyache, adding diagnosis_flu. The measles rules never fire, since has_rash was never in the starting facts — this is forward chaining: each new fact can unlock further rules, until nothing new is left to conclude.

Real Examples: MYCIN

MYCIN, built at Stanford in the 1970s, is one of the earliest and best-known expert systems. It used around 600 rules to help diagnose bacterial infections and recommend antibiotics, working through a backward-chaining dialogue that asked the doctor for exactly the facts it needed to test each rule.

 MYCIN also attached a certainty factor to its conclusions, since medical evidence is rarely 100% conclusive. It was never used on real patients, but studies found its recommendations matched expert judgment about as often as human specialists did.

Quick Summary

PartRole
Knowledge BaseStores facts and IF-THEN rules from a human expert
Inference EngineApplies the rules to reach conclusions
Forward ChainingStarts from facts, works toward a conclusion
Backward ChainingStarts from a goal, works backward to the facts needed
MYCINReal expert system for diagnosing bacterial infections

Frequently Asked Questions

An expert system consists of two primary components: a knowledge base that stores domain facts and IF-THEN rules, and an inference engine that applies reasoning logic to deduce new facts and conclusions.

Forward chaining starts with known facts and fires matching rules to reach conclusions. Backward chaining starts with a specific goal or hypothesis and works backward to see what facts are required to prove it.

MYCIN was an early Stanford-developed expert system from the 1970s that used backward chaining and certainty factors to diagnose bacterial infections and recommend antibiotics.

Separating domain knowledge from reasoning logic makes the rules easy to inspect, explain, and update without having to rewrite or modify the underlying engine code.