Hybrid correction strategy of rules + LLM fallback: why combine two approaches
Bareun's spell checker is a hybrid that combines rule- and dictionary-based correction with LLM correction.
Rules fix most errors quickly and consistently, and only the few eojeol (space-delimited word units) that are hard to resolve by rules are left to the LLM.
This article explains why the two approaches are combined rather than using just one, and how over-correction is prevented.
Why neither rules alone nor an LLM alone is enough
| Approach | Strengths | Weaknesses |
|---|---|---|
| Rules and dictionary | Fast and consistent, can attach evidence (rules), no cost | Weak on neologisms and context-dependent errors not in the dictionary or rules |
| LLM alone | Understands context, strong on unregistered and rare errors | Slow and costly, risk of changing the original too much (over-correction) |
With rules alone you miss errors that are not in the dictionary, and with an LLM alone it is slow and expensive and may change the original arbitrarily. Bareun arranges the two approaches in sequence so each covers the other's weaknesses.
The rule side takes the errors whose nature is clear. Bareun handles with rules and dictionaries: (1) the 14 types of morphological errors caught at the segmentation stage,
(2) spelling rule violations found by NFD (phoneme)-based dictionary search, and (3) non-standard word dictionary correction.
The LLM side takes what rules cannot decide: confusable words that sound alike and cannot be told apart by spelling alone (for example, 반드시/반듯이),
and sentence-level errors that need a whole-sentence view. Splitting the work as "rules for what the orthography rules make clear, the LLM for what needs context" is the core of the combination.
Rules handle most of it
In the early part of the pipeline (rule-based word spacing correction, frequency-based typo, non-standard word, and confusable word checks), rule- and dictionary-based correction runs first.
- Frequency-based typo correction:
스빈다→습니다 - Non-standard word correction:
글장이→글쟁이 - Rule-based word spacing:
아름다운강산→아름다운 강산
Frequently repeated errors with a clear orthographic basis are finished at this stage.
Corrections settled by dictionaries and rules can even carry their basis (rule_article), such as the Standard Korean Language Dictionary and Urimalsaem (the Open Korean Dictionary), so they are highly reliable.
Only UNK, NA, and CONFIRM go to the LLM
Only the eojeol that rules could not settle go on to LLM correction of out-of-vocabulary and unanalyzable eojeol. There are three targets.
| State | Meaning |
|---|---|
UNK | Unclassified: morphological analysis could not decide the part of speech |
NA | Not analyzable: morpheme-level analysis itself failed |
CONFIRM | Needs confirmation: the rule is not confident about the correction and needs further judgment |
Because only a few eojeol are sent to the LLM, this is faster and cheaper than leaving whole sentences to the LLM, and the LLM never ruins parts that rules have already settled.
graph LR
A[Eojeol] --> B{Correction settled<br>by rules?};
B -- Yes --> C[Adopt rule correction<br>attach basis];
B -- No (UNK·NA·CONFIRM) --> D[LLM fallback];
D --> E{Jamo edit distance<br>within threshold?};
E -- Yes --> F[Adopt LLM correction];
E -- No --> G[Reject correction<br>keep original];
Jamo edit distance prevents over-correction
An LLM sometimes returns a result that is plausible but wrong and far from the original. Bareun does not trust LLM results as they are, and verifies them with a Hangul edit distance (Levenshtein distance).
It breaks the original and the LLM result down into Hangul jamo (letter components) and measures the edit distance. If that distance exceeds the threshold (number of characters in the original × 3), it rejects the correction and keeps the original.
Why measure in jamo rather than characters?
A Hangul character is made of an initial consonant, a medial vowel, and a final consonant. If you measure distance in characters, a case where only the final consonant differs, like 밤 and 밥, and
a completely different character both count as "1 character apart." Measured in jamo, a one-final-consonant difference and a wholesale change can be
told apart, so the judgment to allow small typo corrections and reject large changes becomes accurate.
A cache avoids doing the same work twice
LLM call results are stored with MD5 keys in the eojeol correction cache and the word spacing decision cache. When the same eojeol and context come in again, the cache result is used instead of calling the LLM. The default capacity is up to 10,000 entries each.
In summary
Rules handle most of it quickly, the LLM handles only the remaining hard parts, and jamo edit distance blocks over-correction. These three are the core of Bareun's hybrid correction.
Frequently asked questions
Q. Is every eojeol checked by the LLM?
No. Only the eojeol that rules and dictionaries could not settle, namely unclassified (UNK), not analyzable (NA), and needs confirmation (CONFIRM) eojeol,
go to LLM fallback correction. The rest are handled by rules.
Q. What happens if the LLM corrects something wrongly?
LLM results are verified with a Hangul edit distance (Levenshtein distance). If the distance from the original exceeds the threshold (number of characters in the original × 3), the correction is rejected and the original is left as is. This is how over-correction is prevented.
Q. Which errors are handled by rules and which by the LLM?
Errors that are clear from the orthography rules are handled by rules and dictionaries. This includes the 14 types of morphological errors at the segmentation stage, NFD (phoneme)-based dictionary search,
and non-standard word dictionary correction. Errors that need context, such as confusable words that sound alike (반드시/반듯이) and sentence-level errors,
are handled by the LLM.