---
id: wiki-2026-0508-rule-based-systems
title: Rule-based Systems
category: 10_Wiki/Topics
status: verified
canonical_id: self
aliases: [Rule-based AI, Expert Systems, Production Systems]
duplicate_of: none
source_trust_level: A
confidence_score: 0.9
verification_status: applied
tags: [rule-based, expert-systems, symbolic-ai, neuro-symbolic, knowledge]
raw_sources: []
last_reinforced: 2026-05-10
github_commit: pending
tech_stack:
  language: Python
  framework: CLIPS / Drools / experta
---

# Rule-based Systems

## 매 한 줄
> **"매 IF condition THEN action 의 deterministic, auditable knowledge encoding"**. 매 1970s expert systems (MYCIN, DENDRAL, R1/XCON) 의 황금기 → 매 ML winter 후 무대 후퇴 → 매 2024+ neuro-symbolic 부활 (LLM + symbolic constraints, 매 hallucination 통제). 매 finance, healthcare, compliance, fraud 등 매 explainability 가 비협상 의 도메인 의 backbone.

## 매 핵심

### 매 Architecture
- **Working Memory**: facts (current state).
- **Rule Base**: production rules (LHS → RHS).
- **Inference Engine**: forward chaining (data-driven) / backward chaining (goal-driven).
- **Conflict resolution**: salience, recency, specificity.
- **Rete algorithm**: efficient pattern matching (Forgy, 1982).

### 매 Forms
- **Production rules**: CLIPS, Drools, Jess.
- **Decision tables**: tabular form, easy SME edit.
- **Decision trees**: hierarchical, ML-extractable.
- **Logic programming**: Prolog, Datalog, ASP.
- **Business Rule Engines**: Camunda DMN, IBM ODM.

### 매 응용
1. Insurance underwriting / claims adjudication.
2. Loan approval, AML/KYC, sanctions screening.
3. Clinical decision support (drug interactions).
4. Tax/compliance engines.
5. Game AI (NPCs, behavior trees as rule variants).

## 💻 패턴

### CLIPS-style rule (experta)
```python
from experta import KnowledgeEngine, Rule, Fact, Field

class Patient(Fact):
    fever = Field(bool, mandatory=True)
    cough = Field(bool, mandatory=True)
    duration_days = Field(int)

class TriageEngine(KnowledgeEngine):
    @Rule(Patient(fever=True, cough=True, duration_days=lambda d: d >= 7))
    def likely_pneumonia(self):
        self.declare(Fact(diagnosis="pneumonia_suspect", urgent=True))

    @Rule(Patient(fever=True, duration_days=lambda d: d < 3))
    def viral(self):
        self.declare(Fact(diagnosis="viral_likely"))

eng = TriageEngine()
eng.reset()
eng.declare(Patient(fever=True, cough=True, duration_days=8))
eng.run()
```

### Drools rule (DRL syntax)
```java
rule "High value claim escalate"
    when
        $c: Claim(amount > 50000, status == "submitted")
        $p: Policy(id == $c.policyId, riskTier == "HIGH")
    then
        $c.setStatus("escalated_review");
        update($c);
        insert(new Alert("manual_review", $c.getId()));
end
```

### DMN decision table (Camunda)
```xml
<decision id="discount" name="Customer Discount">
  <decisionTable hitPolicy="UNIQUE">
    <input label="Years"><inputExpression typeRef="number">years</inputExpression></input>
    <input label="Tier"><inputExpression typeRef="string">tier</inputExpression></input>
    <output label="Discount" typeRef="number"/>
    <rule><inputEntry>&lt;1</inputEntry><inputEntry>"BRONZE"</inputEntry><outputEntry>0</outputEntry></rule>
    <rule><inputEntry>[1..5]</inputEntry><inputEntry>"SILVER"</inputEntry><outputEntry>0.05</outputEntry></rule>
    <rule><inputEntry>&gt;5</inputEntry><inputEntry>"GOLD"</inputEntry><outputEntry>0.15</outputEntry></rule>
  </decisionTable>
</decision>
```

### Prolog (backward chaining)
```prolog
ancestor(X, Y) :- parent(X, Y).
ancestor(X, Y) :- parent(X, Z), ancestor(Z, Y).

parent(tom, bob).
parent(bob, alice).
% ?- ancestor(tom, alice).  → true
```

### Neuro-symbolic — LLM proposes, rules verify (2026)
```python
import anthropic, json
from rule_engine import compile_rules, evaluate

client = anthropic.Anthropic()
COMPLIANCE_RULES = compile_rules([
    "transaction.amount < 10000 OR transaction.kyc_verified == True",
    "transaction.country NOT IN sanctions_list",
])

resp = client.messages.create(
    model="claude-opus-4-7",
    max_tokens=512,
    messages=[{"role": "user", "content": f"Extract transaction: {raw_text}"}],
)
tx = json.loads(resp.content[0].text)
violations = evaluate(COMPLIANCE_RULES, tx)
if violations:
    block(tx, reasons=violations)  # rules give auditable why
```

### Forward-chaining engine in plain Python
```python
def forward_chain(rules, facts, max_iter=100):
    facts = set(facts)
    for _ in range(max_iter):
        new = set()
        for premises, conclusion in rules:
            if all(p in facts for p in premises) and conclusion not in facts:
                new.add(conclusion)
        if not new:
            break
        facts |= new
    return facts

rules = [
    ({"has_wings", "lays_eggs"}, "is_bird"),
    ({"is_bird", "swims"}, "is_penguin"),
]
print(forward_chain(rules, {"has_wings", "lays_eggs", "swims"}))
# {'has_wings', 'lays_eggs', 'swims', 'is_bird', 'is_penguin'}
```

### Behavior tree (game AI rule variant)
```python
from py_trees import behaviours, composites, common

root = composites.Selector("Root", memory=False)
attack = composites.Sequence("Attack", memory=True, children=[
    behaviours.Condition("EnemyVisible", "EnemyVisible", common.Status.SUCCESS),
    behaviours.Dummy("FireWeapon"),
])
patrol = behaviours.Dummy("Patrol")
root.add_children([attack, patrol])
```

## 매 결정 기준
| 상황 | Approach |
|---|---|
| Auditable, regulated | Rule engine (Drools, DMN) |
| Pattern recognition | ML / DL |
| Hybrid (extract + decide) | LLM + rule verifier (neuro-symbolic) |
| Few thousand cases, frequent change | Decision table |
| Complex ontology | Prolog / Datalog / ASP |

**기본값**: Drools/DMN for business rules, LLM-extract + rule-verify for unstructured input.

## 🔗 Graph
- 부모: [[Symbolic-AI]] · [[Knowledge-Representation]]
- 변형: [[Expert-Systems]]
- Adjacent: [[Neural-Symbolic-Integration|Neuro-Symbolic-AI]]

## 🤖 LLM 활용
**언제**: rule extraction from policy docs, NL-to-DRL translation, rule conflict detection, explanation generation.
**언제 X**: as the rule engine itself in regulated domains — use deterministic engine, let LLM only structure the input.

## ❌ 안티패턴
- **Rule explosion**: 5000+ rules without modules → unmaintainable; refactor to decision tables.
- **Conflicting rules silent**: no conflict detection → undefined behavior.
- **No version control**: rules edited live in production BRMS UI without git.
- **LLM as judge for compliance**: hallucination in regulated path; LLM must propose, rules must verify.

## 🧪 검증 / 중복
- Verified (Russell & Norvig AIMA, CLIPS docs, Drools manual, OMG DMN spec).
- 신뢰도 A.

## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — production rules, Rete, neuro-symbolic 2026 |
