Judgment Engine
The judgment engine is the core of lim’s automation. It takes a business event (a bank transaction, a natural language description, an invoice) and decides how to classify it into a journal entry.
The 4-Step Pipeline
Every transaction passes through four steps, in order. The engine stops at the first step that produces a confident result.
Step 1: Rule Match
The fastest and cheapest step. Rules are deterministic pattern-matching conditions stored in the matching_rule table.
How Rules Work
Each rule has:
- Conditions — Pattern to match (counterparty name, direction, amount range)
- Template — The journal entry to produce (accounts, tax code, amounts)
- Confidence — How reliable this rule is (0.00 to 0.99)
- Auto-post threshold — Confidence level at which entries are posted without human confirmation (default: 0.95)
Example rule:
When a bank transaction with counterparty “Amazon Web Services” arrives, this rule matches on counterparty_contains: "aws" and produces:
Rule Matching Priority
When multiple rules match, they’re evaluated by priority (lower number = higher priority):
Step 2: History Match
When no rule matches, lim searches past journal entries for similar transactions.
The history matcher looks for entries with:
- Similar counterparty name (fuzzy string matching)
- Same direction (inflow/outflow)
- Similar amount range
If a match is found with sufficient similarity, it suggests the same account classification.
History matches always require human confirmation. They never auto-post, even if confidence is
high. This is because the match is probabilistic, not deterministic.
Step 3: AI Inference
When rules and history can’t resolve the transaction, lim calls an LLM to classify it.
The AI receives:
- The transaction details (counterparty, amount, description, date)
- The company’s chart of accounts (codes and names)
- Recent journal entry examples for context
The AI returns:
- Suggested account classification
- Confidence score
- Reasoning
AI inference results always require human confirmation. This is by design — the confirmation is what powers the learning loop.
AI Provider / Model Configuration
The current engine switches AI runtime behavior via LIM_AI_PROVIDER and LIM_AI_MODEL*
environment variables. The LIM_ prefix avoids collisions with generic AI_MODEL settings
used by other tools or services in the same environment. vertex and local are prepared as
injection points, but only the Anthropic adapter is implemented in this slice.
Step 4: Escalate
When all three steps fail to produce a confident classification, the transaction is escalated to a human.
This happens when:
- No rule matches
- No similar history exists
- AI confidence is below 0.60
- The transaction is genuinely ambiguous
Escalated transactions appear as draft journal entries that need manual classification.
Confidence Scores
Confidence scores range from 0.00 to 0.99 and drive automation decisions.
How Confidence Changes
Confidence Thresholds
The Learning Flywheel
The judgment engine improves through a feedback loop:
Learning in Practice
When learnFromConfirmedEntry() is called:
-
Existing rule found (same counterparty pattern) — the rule’s confidence is increased by 0.03 and the template is updated to match the confirmed entry.
-
No existing rule — a new rule is created with:
confidence: 0.85 (starts below auto-post threshold)
source: "learned" (distinguishes from manually created rules)
priority: 50 (lower priority than manual rules)
- Counterparty pattern derived from the confirmed entry
After 4 more confirmations (0.85 + 0.03 x 4 = 0.97), the rule crosses the auto-post threshold and future matching transactions are posted without human input.
Cost Trajectory
For a typical company processing 300 transactions/month:
The key insight: AI costs are front-loaded. The system learns quickly and AI inference becomes
rare. By month 6, most companies see less than $1/month in AI costs for transaction
classification.
Rule Management
Viewing Rules
Manual Rule Creation
For transactions you know in advance, create rules manually for instant classification:
Manual rules have higher priority (lower number) than learned rules, so they take precedence.
Architecture
The judgment engine lives in the @repo/engine package:
Each step is independently testable and the pipeline is extensible — new steps can be inserted without changing the overall flow.