languagetool-org/languagetool · error · BadRequestException
'lang' parameter missing
Error message
'lang' parameter missing
What it means
The GET /v2/ruleExamples endpoint needs the language short code (e.g. en-US, de-DE) to build the JLanguageTool instance for which rule examples are requested. If the 'lang' query parameter is absent, handleRuleExamplesRequest throws a BadRequestException before any further validation.
Source
Thrown at languagetool-server/src/main/java/org/languagetool/server/ApiV2.java:267
limits.getAccount().getDefaultDictionary() != null &&
!limits.getAccount().getDefaultDictionary().isEmpty()) {
dict = limits.getAccount().getDefaultDictionary();
}
boolean deleted;
if("batch".equals(parameters.get("mode"))) { //Experimental
List<String> words = Arrays.asList(parameters.get("words").split("\\s+"));
deleted = db.deleteWordBatch(words, limits.getPremiumUid(),dict);
writeResponse("deleted", deleted, httpExchange);
} else {
deleted = db.deleteWord(parameters.get("word"), limits.getPremiumUid(), dict);
writeResponse("deleted", deleted, httpExchange);
}
}
private void handleRuleExamplesRequest(HttpExchange httpExchange, Map<String, String> params) throws Exception {
ensureGetMethod(httpExchange, "/rule/examples");
if (params.get("lang") == null) {
throw new BadRequestException("'lang' parameter missing");
}
if (params.get("ruleId") == null) {
throw new BadRequestException("'ruleId' parameter missing");
}
Language lang = Languages.getLanguageForShortCode(params.get("lang"));
JLanguageTool lt = new JLanguageTool(lang);
if (textChecker.config.languageModelDir != null) {
lt.activateLanguageModelRules(textChecker.config.languageModelDir);
}
List<Rule> rules = lt.getAllRules();
List<Rule> foundRules = new ArrayList<>();
for (Rule rule : rules) {
if (rule.getId().equals(params.get("ruleId"))) {
foundRules.add(rule);
}
}
if (foundRules.isEmpty()) {
throw new PathNotFoundException("Rule '" + params.get("ruleId") + "' not found for language " + lang +View on GitHub (pinned to 2e990059ce)
Solutions
- Add the 'lang' query parameter with a valid LanguageTool short code, e.g. lang=en-US.
- Check for typos: the key must be exactly 'lang', not 'language'.
- Validate the short code with Languages.getLanguageForShortCode client-side equivalents to ensure the language is supported.
Example fix
// before GET /v2/ruleExamples?ruleId=TOO_LONG_SENTENCE // after GET /v2/ruleExamples?lang=en-US&ruleId=TOO_LONG_SENTENCE
Defensive patterns
Strategy: validation
Validate before calling
if (!params.lang) throw new Error('ruleExamples requires a "lang" short code, e.g. en-US'); Prevention
- Build endpoint URLs from a helper that requires lang and ruleId together.
- Use the exact key 'lang', not 'language'.
- Validate the short code against the supported language list first.
When it happens
Trigger: GET /v2/ruleExamples?ruleId=SOME_RULE without '?lang=xx-YY'; parameter omitted by a template or query builder; calling the endpoint with only ruleId.
Common situations: Clients porting from internal APIs where the language was implicit; generic API explorers that drop empty parameters; typo'd parameter name like 'language' instead of 'lang'.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Missing 'text' or 'data' parameter
- 'ruleId' parameter missing
- Use parameter 'dicts', not 'dict' in GET /words API method.
- Rule '<ruleId>' not found for language <lang> (LanguageTool
- Expected Basic Authentication
AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06).
Data as JSON: /api/errors/a19b4b5e1b28dd10.
Report an issue: GitHub.