{"record":{"id":"29a024e2ff681fa5","repo":"languagetool-org/languagetool","slug":"text-checking-was-stopped-due-to-too-many-errors","errorCode":null,"errorMessage":"Text checking was stopped due to too many errors (more than %.0f%% of words seem to have an error). Are you sure you have set the correct text language? Language set: ${language.getName()}, text length: ${annotatedText.getPlainText().length()}","messagePattern":"Text checking was stopped due to too many errors \\(more than %\\.0f%% of words seem to have an error\\)\\. Are you sure you have set the correct text language\\? Language set: (.+?), text length: (.+?)","errorType":"exception","errorClass":"ErrorRateTooHighException","httpStatus":null,"severity":"error","filePath":"languagetool-core/src/main/java/org/languagetool/JLanguageTool.java","lineNumber":2245,"sourceCode":"                if (!ignoreRanges.contains(ignoreRange)) {\n                  ignoreRanges.add(ignoreRange);\n                }\n                extendedSentenceRange.updateLanguageConfidenceRates(elem.getNewLanguageMatches());\n              }\n              ruleMatches.add(thisMatch);\n              if (listener != null) {\n                listener.matchFound(thisMatch);\n              }\n            }\n          }\n          float errorsPerWord = ruleMatches.size() / (float) wordCounter;\n          if (tmpErrorsPerWord < errorsPerWord) {\n            errorRateLog.add(\"With sentence: \" + (i + 1) + \" (of \" + sentencesSize + \") the text error rate increased by: \" + (errorsPerWord - tmpErrorsPerWord) + \" from: \" + tmpErrorsPerWord  + \" to total: \" + errorsPerWord);\n            tmpErrorsPerWord = errorsPerWord;\n          }\n          if (maxErrorsPerWordRate > 0 && errorsPerWord > maxErrorsPerWordRate && wordCounter > 25) {\n            errorRateLog.forEach(e -> logger.info(LoggingTools.BAD_REQUEST, e));\n            throw new ErrorRateTooHighException(\"Text checking was stopped due to too many errors (more than \" + String.format(\"%.0f\", maxErrorsPerWordRate * 100) +\n              \"% of words seem to have an error). Are you sure you have set the correct text language? Language set: \" + JLanguageTool.this.language.getName() +\n              \", text length: \" + annotatedText.getPlainText().length());\n            //        \", text length: \" + annotatedText.getPlainText().length() + \", common word count: \" + commonWords.getKnownWordsPerLanguage(annotatedText.getPlainText()));\n          }\n        } catch (ErrorRateTooHighException e) {\n          throw e;\n        } catch (StackOverflowError e) {\n          System.out.println(\"Could not check sentence due to StackOverflowError (language: \" + language + \"): <sentcontent>\"\n                  + StringUtils.abbreviate(sentence.analyzed.toTextString(), 10_000) + \"</sentcontent>\");\n          throw e;\n        } catch (Exception e) {\n          throw new RuntimeException(\"Could not check sentence (language: \" + language + \"): <sentcontent>\"\n                  + StringUtils.abbreviate(sentence.analyzed.toTextString(), 500) + \"</sentcontent>\", e);\n        }\n      }\n      return new CheckResults(ruleMatches, ignoreRanges, extendedSentenceRanges);\n    }\n","sourceCodeStart":2227,"sourceCodeEnd":2263,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-core/src/main/java/org/languagetool/JLanguageTool.java#L2227-L2263","documentation":"JLanguageTool aborts checking when the ratio of detected errors to words exceeds maxErrorsPerWordRate (after 25+ words), indicating the wrong language was likely selected. It throws ErrorRateTooHighException after logging the per-sentence error-rate progression.","triggerScenarios":"Running check() on text where more than the configured maxErrorsPerWordRate fraction of words (over a 25-word minimum) produce matches — typically text in a language different from the configured Language.","commonSituations":"Server setups where clients submit text with a wrong/mismatched language code; checking non-natural text (code, random characters) with the wrong language model; misconfigured default language on the API.","solutions":["Detect the correct language first (e.g. LanguageDetector or the /v2/detect endpoint) and re-run check() with it","Raise or disable the threshold via setMaxErrorsPerWordRate(float) if high error rates are expected","Catch ErrorRateTooHighException and return a 'wrong language?' hint to the user"],"exampleFix":"// before\nlt = new JLanguageTool(Languages.getLanguageForShortCode(\"de\"));\nlt.check(englishText); // ErrorRateTooHighException\n// after\nLanguage detected = detectLanguage(englishText);\nlt = new JLanguageTool(detected);\nlt.check(englishText);","handlingStrategy":"try-catch","validationCode":"// pre-check approximate error rate\nList<RuleMatch> probe = lt.check(text.substring(0, Math.min(text.length(), 500)));\nif (((double) probe.size() / text.split(\"\\\\s+\").length) > 0.5) { /* suspect wrong language */ }","typeGuard":null,"tryCatchPattern":"try { lt.check(text); } catch (ErrorRateTooHighException e) { log.warn(\"Wrong language? {}\", e.getMessage()); Language detected = detector.detect(text); lt = new JLanguageTool(detected); /* retry */ }","preventionTips":["Run language detection before checking user-submitted text","Configure a sensible maxErrorsPerWordRate and document it for API users","Treat this exception as a 'wrong language' signal, not a bug — surface it to clients"],"tags":["java","language-detection","error-rate"],"backgroundTag":"invalid-config-value","analyzedSha":"2e990059ce67d5e2a0f7f7ca5d31160c6709df4b","analyzedAt":"2026-09-06T09:20:17.015Z","contentChangedAt":"2026-09-06T09:20:17.015Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}