spring-projects/spring-ai · error · java.lang.IllegalArgumentException

No embedding input is provided - all texts are null or empty

Error message

No embedding input is provided - all texts are null or empty

What it means

GoogleGenAiTextEmbeddingModel.call() filters the input text list for entries with actual content before calling the Gemini embedContent API. If every provided text is null or empty (after filtering with StringUtils.hasText), there is nothing to embed, so the model throws this IllegalArgumentException instead of sending a pointless API request. The Gemini embedding API requires at least one non-empty text per request.

Source

Thrown at models/spring-ai-google-genai-embedding/src/main/java/org/springframework/ai/google/genai/text/GoogleGenAiTextEmbeddingModel.java:172

				// Set task type if specified - this might need to be handled differently
				// as the new SDK might not have a direct taskType field
				// We'll need to check the SDK documentation for this

				EmbedContentConfig config = configBuilder.build();

				// Convert instructions to Content list for embedding
				List<String> texts = embeddingRequest.getInstructions();

				// Validate that we have texts to embed
				if (texts == null || texts.isEmpty()) {
					throw new IllegalArgumentException("No embedding input is provided - instructions list is empty");
				}

				// Filter out null or empty strings
				List<String> validTexts = texts.stream().filter(StringUtils::hasText).toList();

				if (validTexts.isEmpty()) {
					throw new IllegalArgumentException("No embedding input is provided - all texts are null or empty");
				}

				// Call the embedding API with retry
				EmbedContentResponse embeddingResponse = RetryUtils.execute(this.retryTemplate,
						() -> this.genAiClient.models.embedContent(modelName, validTexts, config));

				// Process the response
				// Note: We need to handle the case where some texts were filtered out
				// The response will only contain embeddings for valid texts
				int totalTokenCount = 0;
				List<Embedding> embeddingList = new ArrayList<>();

				// Create a map to track original indices
				int originalIndex = 0;
				int validIndex = 0;

				if (embeddingResponse.embeddings().isPresent()) {
					for (String originalText : texts) {

View on GitHub (pinned to 98a7beda4f)

Solutions

  1. Filter the instructions before building the EmbeddingRequest: texts.stream().filter(StringUtils::hasText).toList(), and skip the call if the result is empty.
  2. Fix the upstream data source so it produces non-empty text (check file reads, DB columns, or chunking logic that emits blank segments).
  3. If empty input is legitimate, guard the call site and return an empty EmbeddingResponse instead of invoking the model.

Example fix

// before
EmbeddingRequest request = new EmbeddingRequest(chunks, options);
EmbeddingResponse response = embeddingModel.call(request);

// after
List<String> validChunks = chunks.stream().filter(StringUtils::hasText).toList();
if (validChunks.isEmpty()) {
    return new EmbeddingResponse(List.of());
}
EmbeddingResponse response = embeddingModel.call(new EmbeddingRequest(validChunks, options));
Defensive patterns

Strategy: validation

Validate before calling

List<String> validTexts = texts == null ? List.of() : texts.stream().filter(StringUtils::hasText).toList();
if (validTexts.isEmpty()) { return new EmbeddingResponse(List.of()); }

Prevention

When it happens

Trigger: Calling call(new EmbeddingRequest(List.of(""), options)) or call(new EmbeddingRequest(List.of(null, ""), options)) — i.e. any EmbeddingRequest whose instructions list contains only null, empty, or whitespace-only strings.

Common situations: Upstream data pipelines producing blank documents (failed file reads, empty DB cells); callers building batches where an earlier filter removed all real texts but left the empty/null placeholders; splitting a document on delimiters that yield empty segments; a List with all-null entries after a failed mapping step.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11). Data as JSON: /api/errors/c56db4aa0093e3d4. Report an issue: GitHub.