alibaba/spring-ai-alibaba · info

Content too long ( characters). Truncating to characters.

Error message

Content too long ({} characters). Truncating to {} characters.

What it means

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.

Solutions

  1. Raise maxContentLength in the WebFetchTool configuration if your model context allows.
  2. Fetch a more specific URL/anchor or extract only the needed section instead of the whole page.
  3. If the answer is likely near the end, re-fetch with pagination or a search-targeted query.
  4. Accept truncation when only the top of the page matters.

Example fix

// before
WebFetchTool tool = WebFetchTool.builder().build();
// after
WebFetchTool tool = WebFetchTool.builder().maxContentLength(100_000).build();
Defensive patterns

Strategy: validation

Validate before calling

if (expectedContentLength > tool.getMaxContentLength()) { /* raise limit or fetch narrower page */ }

Prevention

When it happens

Trigger: Calling the web fetch tool (apply) on a page whose extracted text exceeds the configured maxContentLength.

Common situations: 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.

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


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/4d30aefc2ec29f26. Report an issue: GitHub.

Appendix: source

Thrown at spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/tools/WebFetchTool.java:388

		try {
			String response = this.chatClient.prompt()
				.user(u -> u.text(FETCH_SUMMARIZE_PROMPT).param("content", content).param("userQuery", userQuery))
				.call()
				.content();
			return response != null ? response : "Error: Received empty response from AI model";
		}
		catch (Exception e) {
			logger.error("Failed to summarize content", e);
			return "Error summarizing content: " + e.getMessage();
		}
	}

	private String truncate(String content) {
		if (content == null) {
			return "";
		}
		if (content.length() > this.maxContentLength) {
			logger.warn("Content too long ({} characters). Truncating to {} characters.", content.length(),
					this.maxContentLength);
			return content.substring(0, this.maxContentLength);
		}
		return content;
	}

	/**
	 * Custom exception for web fetch errors.
	 */
	public static class WebFetchException extends RuntimeException {

		public WebFetchException(String message, Throwable cause) {
			super(message, cause);
		}

	}

	public static Builder builder(ChatClient chatClient) {

View on GitHub (pinned to f82da0b50f)