{"record":{"id":"4d30aefc2ec29f26","repo":"alibaba/spring-ai-alibaba","slug":"content-too-long-characters-truncating-to","errorCode":null,"errorMessage":"Content too long ({} characters). Truncating to {} characters.","messagePattern":"Content too long \\((.+?) characters\\)\\. Truncating to (.+?) characters\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"info","filePath":"spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/tools/WebFetchTool.java","lineNumber":388,"sourceCode":"\t\ttry {\n\t\t\tString response = this.chatClient.prompt()\n\t\t\t\t.user(u -> u.text(FETCH_SUMMARIZE_PROMPT).param(\"content\", content).param(\"userQuery\", userQuery))\n\t\t\t\t.call()\n\t\t\t\t.content();\n\t\t\treturn response != null ? response : \"Error: Received empty response from AI model\";\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tlogger.error(\"Failed to summarize content\", e);\n\t\t\treturn \"Error summarizing content: \" + e.getMessage();\n\t\t}\n\t}\n\n\tprivate String truncate(String content) {\n\t\tif (content == null) {\n\t\t\treturn \"\";\n\t\t}\n\t\tif (content.length() > this.maxContentLength) {\n\t\t\tlogger.warn(\"Content too long ({} characters). Truncating to {} characters.\", content.length(),\n\t\t\t\t\tthis.maxContentLength);\n\t\t\treturn content.substring(0, this.maxContentLength);\n\t\t}\n\t\treturn content;\n\t}\n\n\t/**\n\t * Custom exception for web fetch errors.\n\t */\n\tpublic static class WebFetchException extends RuntimeException {\n\n\t\tpublic WebFetchException(String message, Throwable cause) {\n\t\t\tsuper(message, cause);\n\t\t}\n\n\t}\n\n\tpublic static Builder builder(ChatClient chatClient) {","sourceCodeStart":370,"sourceCodeEnd":406,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/tools/WebFetchTool.java#L370-L406","documentation":"truncate in WebFetchTool detected fetched content exceeding maxContentLength characters and logged this warning while shortening the content to the limit before returning it to the model. This protects the model context window but silently drops trailing content.","triggerScenarios":"Calling the web fetch tool (apply) on a page whose extracted text exceeds the configured maxContentLength.","commonSituations":"Fetching very large documentation pages, long transcripts, or raw JSON endpoints where the relevant info is past the truncation point, so the model sees incomplete data.","solutions":["Raise maxContentLength in the WebFetchTool configuration if your model context allows.","Fetch a more specific URL/anchor or extract only the needed section instead of the whole page.","If the answer is likely near the end, re-fetch with pagination or a search-targeted query.","Accept truncation when only the top of the page matters."],"exampleFix":"// before\nWebFetchTool tool = WebFetchTool.builder().build();\n// after\nWebFetchTool tool = WebFetchTool.builder().maxContentLength(100_000).build();","handlingStrategy":"validation","validationCode":"if (expectedContentLength > tool.getMaxContentLength()) { /* raise limit or fetch narrower page */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set maxContentLength according to your model's context budget.","Fetch targeted URLs instead of huge index pages.","Do not rely on content beyond the truncation point being visible to the model."],"tags":["truncation","webfetch","content-length"],"backgroundTag":"payload-too-large","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}