languagetool-org/languagetool · error · BadRequestException

'ruleId' parameter missing

Error message

'ruleId' parameter missing

What it means

GET /v2/ruleExamples requires both 'lang' and 'ruleId'. After the 'lang' check, the handler verifies 'ruleId' and throws a BadRequestException if it is missing, because it cannot select which rule's examples to return.

Source

Thrown at languagetool-server/src/main/java/org/languagetool/server/ApiV2.java:270

    }
    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 +
              " (LanguageTool version/date: " + JLanguageTool.VERSION + "/" + JLanguageTool.BUILD_DATE + ", total rules of language: " + rules.size() + ")");
    }
    StringWriter sw = new StringWriter();

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Append ruleId=<id> to the query string, e.g. ruleId=TOO_LONG_SENTENCE.
  2. Take the exact 'id' value returned by GET /v2/rules as the ruleId value.
  3. Ensure correct casing: 'ruleId' with lowercase 'r' and uppercase 'I'.

Example fix

// before
GET /v2/ruleExamples?lang=en-US
// after
GET /v2/ruleExamples?lang=en-US&ruleId=TOO_LONG_SENTENCE
Defensive patterns

Strategy: validation

Validate before calling

if (!params.ruleId) throw new Error('ruleExamples requires a "ruleId" query parameter');

Prevention

When it happens

Trigger: GET /v2/ruleExamples?lang=en-US without a ruleId; passing the rule name in the path or body instead of the 'ruleId' query parameter; misspelling it as 'rule' or 'ruleID'.

Common situations: Iterating over rules and forgetting to forward the id to the examples endpoint; clients confusing /v2/rules output field 'id' with a differently named parameter.

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


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