g↗genai/ learner
How Machines Learn / Lesson 08

Knowledge, rules and reasoning

Not every AI system learns from examples alone. Explicit facts and rules give systems traceable logic—and today they often work alongside learned models.

Concept + interactive labBeginner friendly

Facts, rules, and explicit reasoning.

Earlier in this chapter, you saw models that learn statistical patterns from data. Another branch of AI works differently: people store explicit statements and clear if-then instructions so a system can deduce answers step by step.

In this lesson, you will follow five ideas in order: a fact, a rule, chaining, a knowledge graph, and a hybrid system that pairs rules with learned models.

Stored fact

An explicit statement the system starts with—for example, a recipe record linking a pastry to an ingredient.

Rule

An explicit if-then instruction: when its conditions match known facts, it produces a new statement or warning.

Derived fact

A new statement produced by a rule rather than typed in directly, which another rule can then use.

For an everyday example, consider a fictional bank rule: if a customer’s total transfers for the day—including a proposed new transfer—would exceed a stated threshold, require a second confirmation. The rule is explicit, repeatable, and easy to audit.

Running example: Mina’s Neighborhood Bakery

Mina (an invented bakery owner for this lesson) keeps a simple digital recipe record to help staff check pastries for tree nuts. For this exercise, the record lists almonds and walnuts as tree nuts, oats as a grain, and uses “made from” to record what a prepared ingredient contains.

Suppose Mina’s system starts with three stored facts for the Almond Croissant: Almond Croissant contains Almond Paste, Almond Paste is made from Almonds, and Almonds is a Tree Nut. Notice that no single stored fact says the croissant contains a tree nut.

  • Rule A (Unpack a prepared ingredient)Because Almond Croissant contains Almond Paste and Almond Paste is made from Almonds, Rule A applies and produces the derived fact: Almond Croissant contains Almonds. Written generally: if a pastry contains X and X is made from Y, then the pastry contains Y.
  • Rule B (Tree-nut warning)Because Almond Croissant contains Almonds (derived by Rule A) and Almonds is a Tree Nut (stored), Rule B applies (fires) and raises a warning (flag): Contains tree nuts.

This step-by-step process is called forward chaining: the rule engine starts from available facts, applies any rule whose conditions match, adds the derived facts, and keeps checking until it can derive nothing new.

Diagram titled Chaining facts with rules: Stored facts (Almond Croissant contains Almond Paste, Almond Paste made from Almonds, Almonds is a Tree Nut) flow into Forward chaining where Rule A produces Derived: contains Almonds and passes it to Rule B (Matches Tree Nut), leading to Result: Contains tree nuts with a Traceable path. Bottom cards show an allergy checklist analogy and three key takeaways.
Forward chaining links stored facts through explicit rules so this warning carries a step-by-step trace.

Connecting facts in a knowledge graph.

As Mina adds more pastries, keeping facts as scattered sentences gets hard to maintain. A knowledge graph organizes information as a network of nodes (things such as Almond Croissant, Almonds, or Tree Nut) connected by labelled edges (relationships such as contains, made from, or is a). A fact in this graph is the full statement joining two nodes through a named relationship—for example, Almond Paste — made from → Almonds.

Think of a movie catalog linking actors, films, and directors: once each person and film is a node, you can follow connections across several hops without repeating the same facts on every page.

In Mina’s bakery graph, both Almonds and Walnuts point to the same shared Tree Nut node. Storing the links is separate from applying rules: the graph holds the recorded relationships, while Rule A authorizes the new contains Almonds link and Rule B checks whether any direct or derived ingredient connects to Tree Nut.

Diagram titled Knowledge graph: eight labelled edges connect pastries to categories. Almond Croissant contains Almond Paste; Almond Paste made from Almonds; Almonds is a Tree Nut; Walnut Brownie contains Walnuts; Walnuts is a Tree Nut (sharing the Tree Nut node); Oat Muffin contains Rolled Oats; Rolled Oats made from Oats; Oats is a Grain. Bottom cards show a transit-map analogy (stations are things, lines are links) and three key takeaways.
A knowledge graph stores reusable relationships; rules then walk those stored links to derive new facts or warnings.

Chain facts with rules in Mina’s bakery.

Try the toy rule engine below. Like a checklist that only knows what is written on the sheet, the engine recomputes its reasoning trace from scratch whenever you toggle a stored fact or a rule.

  1. Start on Almond Croissant and read how Rule A creates the derived fact Almond Croissant contains Almonds before Rule B raises the warning.
  2. Click Almond Paste — made from → Almonds to remove that stored fact and see where the chain stops.
  3. Turn that fact back on, then turn off Rule A. Notice that Almond Croissant loses its warning, while switching to Walnut Brownie still triggers Rule B directly.
  4. Switch to Oat Muffin with both rules on: Rule A derives Oat Muffin contains Oats, while Rule B finds no enabled is a → Tree Nut classification for its ingredients (even if you toggle Oats — is a → Grain off, the verdict stays the same).
Toy rule engine: Mina’s recipe checker
1. Choose a pastry
2. Stored facts for Almond Croissant (toggle to simulate missing records)
3. Enabled rules (recomputes immediately)
Reasoning traceFlagged: Contains tree nuts
  1. Rule A applied: from “Almond Croissant contains Almond Paste” and “Almond Paste made from Almonds”, derived new fact: “Almond Croissant contains Almonds”.
  2. Rule B applied: combined derived fact “Almond Croissant contains Almonds” with stored fact “Almonds is a Tree Nut” → Warning: Contains tree nuts.

Two rules chained together: Rule A derived the hidden ingredient, and Rule B matched it against the Tree Nut category.

Simplified toy engine for learning only—not a real allergen safety tool. It only checks the stored facts toggled on above and cannot detect unrecorded ingredients or cross-contact (ingredient transfer through shared kitchen equipment).

Why rules are not obsolete: hybrid AI systems.

Because modern neural networks can write essays and recognize images, it is easy to assume rule-based systems are obsolete. In practice, explicit rules remain widely used—sometimes on their own (like the bank transfer threshold above) and often paired with learned models in a hybrid system.

Where learned models shine

Handling messy everyday language, typos, photos, and fuzzy patterns that are too varied to write down as hand-crafted rules.

Where facts and rules shine

Enforcing strict policies, checking exact records, and acting as a rule gate—a required check before an action or reply proceeds—with a clear trace of why it applied.

In real-world payment systems, for example, Stripe Radar combines machine-learning risk scoring with explicit merchant-defined rules that can block or review specific payments.

Mina’s bakery helper as a hybrid system

A customer selects the Almond Croissant in the ordering app and types: “Is this safe for my tree-nut allergy?” First, a learned language model reads the question and maps it to the selected item (Almond Croissant) and allergen category (Tree Nut). Next, the knowledge graph and rules check the recipe record and flag Contains tree nuts. Finally, the app renders that finding in a fixed response template: “Contains tree nuts: the bakery’s recipe record shows that the almond paste in the Almond Croissant is made from almonds.”

Using a fixed template—or checking generated wording against the rule engine’s output—helps keep the final reply aligned with the checked record. Even so, the rule engine only shows what follows from the selected item, its enabled records, and its active rules.

Diagram titled Hybrid AI system: four left-to-right cards show Question (Almond Croissant and tree nuts?) flowing to Learned model (Reads wording), then to Facts and rules (Checks record), then to Template reply (Contains tree nuts). Bottom cards show a clerk-with-recipe-binder analogy and three key takeaways.
A hybrid system lets a learned model handle natural language while explicit facts, rules, and templates keep the policy check traceable.

Limits and quick questions.

Combining rules with learned models is powerful, yet every part still has clear limits:

  • Missing or stale facts: If a supplier changes a recipe and nobody updates the knowledge graph, the rule engine can miss an allergen even when every rule works correctly.
  • Fuzzy visual or judgment tasks: Explicit rules work well for precise conditions, such as a transfer threshold. Judging whether a croissant baked evenly from a photo is harder to capture in rules.
  • Hybrid handoff errors: If a customer asks vaguely about “that flaky morning pastry” without selecting an item and the learned model guesses the wrong pastry, the rule engine checks the wrong record.
  • Did deep learning replace rule-based systems?

    No. Standalone rules still handle clear-cut policies like transfer thresholds, and hybrid systems pair learned models with explicit rules whenever strict checks and audit trails matter.

  • Is a knowledge graph the same thing as a table?

    A knowledge graph organizes facts around named relationships, and those same relationships can also be stored as rows in a table. For example, the arrow Almond Paste — made from → Almonds can be written as a three-column row:

    SubjectRelationObject
    Almond Pastemade fromAlmonds
  • If no warning appears, does that guarantee a pastry is allergen-free?

    No. A warning can be absent either because the check itself was disabled (Rule B off) or because the enabled facts did not match a tree-nut rule. Unrecorded ingredients or cross-contact (ingredient transfer through shared kitchen equipment) are outside what the rule engine knows.

✎ Try it yourselfKnowledge check · Practice only

Check your understanding.

A fictional clinic wants an assistant that lets patients request prescription refills in everyday language, but may submit a restricted-medication refill only when a current doctor approval is confirmed in the clinic’s records. Which design fits both requirements best?

Take this with you.

Rules and learned models solve different halves. Explicit facts, rules, and knowledge graphs give you repeatable, traceable logic—and hybrid systems pair them with learned models so everyday language and strict policy checks work together.

Ready to continue? Return to How Machines Learn.