STAYCHARTED BLOG · Machine learning · Rules and automation
How to convert a rule-based system into a trained model, without losing the rules you need
Your rules' history is already training data. Six steps to move judgment calls from if-then rules to a trained model, keep policy rules, and test first.
Step 1: Sort your rules into policy and guesses
Go through the rules, or a sample of them, and put each in one of two piles.
Policy rules: keep them.
- Based on a law, a contract, a threshold or a hard business decision.
- Exact conditions: an amount, a country, a customer tier, a code.
- Example: "Invoices over $10,000 need controller approval." "Anything mentioning a breach goes to Security."
Guess rules: candidates to replace.
- Based on keywords, "contains", or a mapping table someone maintains.
- They exist because someone read past items and wrote down a pattern.
- Example: "If the description contains 'adobe' or 'figma', code it to Software." "If the subject contains 'login', route to Service Desk."
Guess rules are a person's summary of the history. A model can learn that history directly, including the patterns nobody wrote down.
Step 2: Export the history, with the final answers
Export 6 to 12 months of items the rules have handled:
- the text a person would read (subject, description, vendor name, product title);
- any fields that matter (amount band, location, customer type);
- the final answer: where it ended up after any person moved it.
The final answer is the label. Items a person corrected are the most valuable rows in the file, because they're exactly where the rules were wrong.
Remove personal information you don't need. StayCharted also finds and can mask email addresses, phone numbers and similar before training. Remove personal information from training data →
Step 3: Train, and read the report honestly
Upload the file, choose the columns to read and the column with the answer, and train. The report shows:
- accuracy on items the model never trained on;
- accuracy for each category, weakest first;
- the categories it mixes up;
- how many items would go to a person at each confidence cutoff, and the projected accuracy after review, assuming those reviews are correct.
Weak categories usually mean too few examples or labels that disagree. Fix the data, not the model. How many examples do I need? →
Step 4: Run it beside the rules (shadow mode)
Before switching anything, compare on the same recent items:
- Train on items decided before a date, for example the start of last month.
- Fill last month's items with the model.
- Compare the model's answer and the rules' answer with the final answer your team settled on.
For each category you'll see one of three things: the model wins, the rules win, or they tie. StayCharted’s scored test fill compares the model with your known answers. Separately compare the rules’ outputs with the same answers to measure both approaches. Train on the past, test on the future →
Step 5: Switch category by category, with a cutoff
Turn off the guess rules only for the categories where the model wins. Then set a confidence cutoff:
- above it, the model's answer is used, and your remaining policy rules still apply on top;
- below it, the item goes to a person, exactly as an unmatched item did before.
The order in production is usually: policy rules first (anything they decide is final), then the model for the rest, then a person for anything below the cutoff.
Step 6: Let corrections teach the next version
The old rule system needed someone to write a new rule for each miss. Now every correction a person makes in the Review Queue becomes a training example for the next version, and a Builder publishes the new version after checking its report. How review and retraining work →
Retrain when something changes, such as a new product line, a new team or a reorganized chart of accounts, and keep testing on the most recent month.
What to keep as rules, always
- Legal and regulatory requirements.
- Approval thresholds and segregation of duties.
- Anything that must be explained line by line to an auditor or a customer.
- Safety overrides: "known exploited", "data breach", "VIP customer".
A model's job is the judgment in between. Rule-based system vs machine learning →
Where this applies
Explore the rules vs machine learning series
- Rule-Based System vs Machine Learning: When Rules Stop Scaling
- ServiceNow Assignment Rules vs Machine Learning: When to Switch
- GL Coding Rules vs Machine Learning: Where Vendor Rules Fail
- QuickBooks Bank Rules vs AI Categorization: When to Switch
- Outlook Rules vs AI for Shared Inbox Routing: When to Switch
- Keyword Tables vs Machine Learning for UNSPSC and HS Codes
Common questions
Do we have to turn off all our rules at once?
No. Switch category by category, only where the model measurably does better, and keep policy rules for good.
What if our rules were wrong for a long time?
Train on the final answers after people's corrections, not on what the rules said. If nobody corrected them, the model will learn the same mistakes, so check a sample of labels first.
Can we explain a model's decision like we explain a rule?
Not line by line. You can show its confidence, the similar past items your team decided, and its measured accuracy per category. For decisions that need a line-by-line explanation, keep a rule.
How long does this take?
The export is usually the longest part. Training and test time depend on the data, model and workload; start with a representative export and measure the end-to-end process.