Grammar and Spell Check Implementation
Grammar and spell checking—task where simple tools cover 80% of cases, remaining 20% (contextual errors, style, agreement) require language models.
Tools by Complexity Level
Spelling only (dictionary check):
-
pyspellchecker—small dictionary, works without ML, 1ms/word -
enchant(Python)—interface to system dictionaries (Hunspell), good Russian coverage -
autocorrect—simple replacement with Edit Distance
Spelling + grammar (rule-based systems):
-
LanguageTool—open-source, Java, REST API. 2500+ rules for Russian, supported via
language-tool-python. Best choice for production without LLM.
import language_tool_python
tool = language_tool_python.LanguageTool("ru-RU")
matches = tool.check("I went to the store for bred.")
# Match: "bred" → "bread" (Rule: MORFOLOGIK_RULE_EN_US)
LLM-based (best quality):
- GPT-4o or Claude for contextual errors, style
- Prompt: "Fix grammar and spelling errors. Return corrected text and change list in JSON"
Russian Language Specifics
Russian grammar complex for algorithmic checking: case management, adjective-noun agreement, comma placement. LanguageTool covers most common cases, LLM handles nuances.
For punctuation checking: Yandex.Speller API (free, spelling only) + LanguageTool (punctuation). Combined use increases recall.
Editor Architecture
In text editor, checking happens asynchronously. Underlining appears 500ms after input stops. Fast first pass (LanguageTool, < 100ms)—spelling and basic grammar. Second pass (LLM, 1–3s)—contextual errors and style. Suggestion UI with hotkeys for quick fix acceptance.







