languagetool-org/languagetool · error · TextTooLongException
Your text's length exceeds this server's hard limit of char
Error message
Your text's length exceeds this server's hard limit of characters.
What it means
Thrown when the raw request body (all posted parameters combined) exceeds the server's hard maximum length. This is a protective limit to prevent out-of-memory conditions from oversized uploads; it is independent of the configurable maxTextLength for the text itself.
Source
Thrown at languagetool-server/src/main/java/org/languagetool/server/LanguageToolHttpHandler.java:468
}
}
private String readerToString(Reader reader, int maxTextLength) throws IOException {
StringBuilder sb = new StringBuilder();
char[] chars = new char[4000];
while (true) {
int readBytes = reader.read(chars, 0, 4000);
if (readBytes <= 0) {
break;
}
int generousMaxLength = maxTextLength * 10; // one character can be encoded as e.g. "%D8", plus estimated space for sending data (JSON)
if (generousMaxLength < 0) { // might happen as it can overflow
generousMaxLength = Integer.MAX_VALUE;
}
if (sb.length() > 0 && sb.length() > generousMaxLength) {
// don't stop at maxTextLength as that's the text length, but here also other parameters
// are included (still we need this check here so we don't OOM if someone posts a few hundred MB)...
throw new TextTooLongException("Your text's length exceeds this server's hard limit of " + generousMaxLength + " characters.");
}
sb.append(new String(chars, 0, readBytes));
}
return sb.toString();
}
private Map<String, String> parseQuery(String query, HttpExchange httpExchange) throws UnsupportedEncodingException {
Map<String, String> parameters = new HashMap<>();
if (query != null) {
parameters.putAll(getParameterMap(query, httpExchange));
}
return parameters;
}
private Map<String, String> getParameterMap(String query, HttpExchange httpExchange) throws UnsupportedEncodingException {
String[] pairs = StringUtils.split(query, '&');
Map<String, String> parameters = new HashMap<>();View on GitHub (pinned to 2e990059ce)
Solutions
- Reduce the submitted text size or split it into chunks below the server's limit
- Increase the server's --requestLimit (request size) setting if larger payloads are legitimate
- Check the client for accidental duplicate/concatenated payloads on retries
Example fix
// before POST /v2/check with text=<10GB document> // after POST /v2/check with text=<first 50KB chunk>, repeat per chunk
Defensive patterns
Strategy: validation
Validate before calling
const MAX = 100 * 1024 * 1024; // match server requestSizeLimit
const body = new URLSearchParams({ text, language });
if (body.toString().length > MAX) throw new Error('Payload exceeds server hard limit; chunk the text'); Try / catch
try {
return await check(text);
} catch (e) {
if (e.message.includes('hard limit')) {
return Promise.all(chunkText(text).map(check)); // split and retry
}
throw e;
} Prevention
- Chunk large documents before sending
- Set client-side max payload checks matching the server config
- Avoid retry loops that resend oversized bodies
When it happens
Trigger: POST body larger than generousMaxLength (requestSizeLimit), e.g. a text parameter with hundreds of MB, or many/large parameters combined.
Common situations: Submitting very large documents in a single request, batch jobs sending unbounded text, clients retrying and concatenating payloads, or misconfigured requestSizeLimit that overflows to a low value.
Understand the failure class
Background: payload too large / request exceeds maximum size: why libraries cap bytes and how to fix oversize payloads — this error's family across 50 libraries.
Related errors
- Missing 'text' or 'data' parameter
- Use parameter 'dicts', not 'dict' in GET /words API method.
- 'lang' parameter missing
- 'ruleId' parameter missing
- Rule '<ruleId>' not found for language <lang> (LanguageTool
AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06).
Data as JSON: /api/errors/82e8c692e5ddff3c.
Report an issue: GitHub.