languagetool-org/languagetool · error · RuntimeException

Could not load language model capable rules.

Error message

Could not load language model capable rules.

What it means

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.

Source

Thrown at languagetool-core/src/main/java/org/languagetool/JLanguageTool.java:602

      }
    }
  }

  /**
   * Remove rules that can profit from a language model, recreate them with the given model and add them again
   *
   * @param lm the language model or null if none is available
   */
  private void updateOptionalLanguageModelRules(@Nullable LanguageModel lm) {
    ResourceBundle messages = getMessageBundle(language);
    try {
      List<Rule> rules = language.getRelevantLanguageModelCapableRules(messages, lm, globalConfig, userConfig, motherTongue, altLanguages);
      userRules.removeIf(rule -> optionalLanguageModelRules.contains(rule.getId()));
      optionalLanguageModelRules.clear();
      rules.stream().map(Rule::getId).forEach(optionalLanguageModelRules::add);
      userRules.addAll(rules);
    } catch (Exception e) {
      throw new RuntimeException("Could not load language model capable rules.", e);
    }
    ruleSetCache.clear();
  }

  /**
   * Activate rules that depend on a language model. The language model currently
   * consists of Lucene indexes with ngram occurrence counts.
   *
   * @param indexDir directory with a '3grams' sub directory which contains a Lucene index with 3gram occurrence counts
   * @since 2.7
   */
  public void activateLanguageModelRules(File indexDir) throws IOException {
    LanguageModel languageModel = language.getLanguageModel(indexDir);
    if (languageModel != null) {
      ResourceBundle messages = getMessageBundle(language);
      List<Rule> rules = language.getRelevantLanguageModelRules(messages, languageModel, userConfig);
      userRules.addAll(rules);
      updateOptionalLanguageModelRules(languageModel);

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Read the 'Caused by' to see whether model files or rule definitions failed.
  2. Verify the language model directory exists and is populated; fix the model path passed to activateLanguageModelRules/JLanguageTool.
  3. If you do not need model-based rules, construct JLanguageTool without a language model (withLanguageModel=false path starts without them).
  4. Align LanguageTool and language-model resource versions.

Example fix

// before
lt.activateLanguageModelRules(new File("/opt/lm")); // dir does not exist
// after
File lm = new File("/opt/lm");
if (lm.isDirectory() && lm.list().length > 0) { lt.activateLanguageModelRules(lm); }
Defensive patterns

Strategy: validation

Validate before calling

File lmDir = new File(modelPath);
if (!lmDir.isDirectory() || lmDir.list().length == 0) {
  throw new IllegalArgumentException("language model directory missing or empty: " + modelPath);
}

Try / catch

try {
  lt.activateLanguageModelRules(lmDir);
} catch (RuntimeException e) {
  logger.error("Could not load language-model rules; continuing without them", e);
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06). Data as JSON: /api/errors/bca62c48d600782d. Report an issue: GitHub.