{"record":{"id":"bca62c48d600782d","repo":"languagetool-org/languagetool","slug":"could-not-load-language-model-capable-rules","errorCode":null,"errorMessage":"Could not load language model capable rules.","messagePattern":"Could not load language model capable rules\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"languagetool-core/src/main/java/org/languagetool/JLanguageTool.java","lineNumber":602,"sourceCode":"      }\n    }\n  }\n\n  /**\n   * Remove rules that can profit from a language model, recreate them with the given model and add them again\n   *\n   * @param lm the language model or null if none is available\n   */\n  private void updateOptionalLanguageModelRules(@Nullable LanguageModel lm) {\n    ResourceBundle messages = getMessageBundle(language);\n    try {\n      List<Rule> rules = language.getRelevantLanguageModelCapableRules(messages, lm, globalConfig, userConfig, motherTongue, altLanguages);\n      userRules.removeIf(rule -> optionalLanguageModelRules.contains(rule.getId()));\n      optionalLanguageModelRules.clear();\n      rules.stream().map(Rule::getId).forEach(optionalLanguageModelRules::add);\n      userRules.addAll(rules);\n    } catch (Exception e) {\n      throw new RuntimeException(\"Could not load language model capable rules.\", e);\n    }\n    ruleSetCache.clear();\n  }\n\n  /**\n   * Activate rules that depend on a language model. The language model currently\n   * consists of Lucene indexes with ngram occurrence counts.\n   *\n   * @param indexDir directory with a '3grams' sub directory which contains a Lucene index with 3gram occurrence counts\n   * @since 2.7\n   */\n  public void activateLanguageModelRules(File indexDir) throws IOException {\n    LanguageModel languageModel = language.getLanguageModel(indexDir);\n    if (languageModel != null) {\n      ResourceBundle messages = getMessageBundle(language);\n      List<Rule> rules = language.getRelevantLanguageModelRules(messages, languageModel, userConfig);\n      userRules.addAll(rules);\n      updateOptionalLanguageModelRules(languageModel);","sourceCodeStart":584,"sourceCodeEnd":620,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-core/src/main/java/org/languagetool/JLanguageTool.java#L584-L620","documentation":"updateOptionalLanguageModelRules loads rules capable of using a language model (e.g. neural rules) via language.getRelevantLanguageModelCapableRules; any Exception is rethrown as this RuntimeException. It means rules that depend on the (possibly null) language model could not be loaded, so the instance cannot be (re)configured.","triggerScenarios":"Constructing JLanguageTool with a language-model configuration, or calling activateLanguageModelRules(...), when the language's model-capable rule loader throws (missing model files, bad rule definitions, IO/config errors).","commonSituations":"Language model directory missing, empty, or wrong path in the configuration; ngram/neural rule resources absent for the language; mismatched LanguageTool versions where the rule expects a different model layout.","solutions":["Read the 'Caused by' to see whether model files or rule definitions failed.","Verify the language model directory exists and is populated; fix the model path passed to activateLanguageModelRules/JLanguageTool.","If you do not need model-based rules, construct JLanguageTool without a language model (withLanguageModel=false path starts without them).","Align LanguageTool and language-model resource versions."],"exampleFix":"// before\nlt.activateLanguageModelRules(new File(\"/opt/lm\")); // dir does not exist\n// after\nFile lm = new File(\"/opt/lm\");\nif (lm.isDirectory() && lm.list().length > 0) { lt.activateLanguageModelRules(lm); }","handlingStrategy":"validation","validationCode":"File lmDir = new File(modelPath);\nif (!lmDir.isDirectory() || lmDir.list().length == 0) {\n  throw new IllegalArgumentException(\"language model directory missing or empty: \" + modelPath);\n}","typeGuard":null,"tryCatchPattern":"try {\n  lt.activateLanguageModelRules(lmDir);\n} catch (RuntimeException e) {\n  logger.error(\"Could not load language-model rules; continuing without them\", e);\n}","preventionTips":["Verify the model directory is populated before activation.","Match model resource layout to your LanguageTool version.","Decide explicitly whether model rules are optional and handle failure gracefully."],"tags":["language-model","rules","initialization","runtime-exception"],"backgroundTag":"missing-dependency","analyzedSha":"2e990059ce67d5e2a0f7f7ca5d31160c6709df4b","analyzedAt":"2026-09-06T09:20:17.015Z","contentChangedAt":"2026-09-06T09:20:17.015Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}