spring-projects/spring-ai · error · java.lang.IllegalArgumentException
No embedding input is provided - instructions list is empty
Error message
No embedding input is provided - instructions list is empty
What it means
GoogleGenAiTextEmbeddingModel.call() validates the EmbeddingRequest's instructions before sending them to the Google GenAI API. If the instructions list is null or empty there is nothing to embed, so the model throws IllegalArgumentException instead of issuing a pointless or failing API request.
Source
Thrown at models/spring-ai-google-genai-embedding/src/main/java/org/springframework/ai/google/genai/text/GoogleGenAiTextEmbeddingModel.java:165
EmbedContentConfig.Builder configBuilder = EmbedContentConfig.builder();
// Set dimensions if specified
if (options.getDimensions() != null) {
configBuilder.outputDimensionality(options.getDimensions());
}
// 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<>();View on GitHub (pinned to 98a7beda4f)
Solutions
- Ensure the EmbeddingRequest contains at least one non-empty instruction string before calling the model
- Guard upstream batch logic to skip or reject empty batches
- Check that document splitting/retrieval actually produced content (files not empty, not filtered out)
Example fix
// before
EmbeddingRequest req = new EmbeddingRequest(List.of(), EmbeddingOptionsBuilder.builder().build());
model.embed(req); // throws
// after
if (!texts.isEmpty()) {
EmbeddingRequest req = new EmbeddingRequest(texts, EmbeddingOptionsBuilder.builder().build());
model.embed(req);
} Defensive patterns
Strategy: validation
Validate before calling
List<String> texts = embeddingRequest.getInstructions();
if (texts == null || texts.isEmpty()) {
throw new IllegalArgumentException("EmbeddingRequest must contain at least one instruction");
} Type guard
boolean hasEmbeddingInput(EmbeddingRequest req) { return req.getInstructions() != null && !req.getInstructions().isEmpty(); } Try / catch
try { model.embed(request); } catch (IllegalArgumentException e) { if (e.getMessage().contains("instructions list is empty")) { return EmbeddingResponse.empty(); } throw e; } Prevention
- Check batch/document lists for emptiness before embedding
- Ensure upstream chunking/parsing actually yields content
- Guard conditional request-building code paths
When it happens
Trigger: Calling embed()/call() with an EmbeddingRequest constructed with an empty list of instructions or null instructions.
Common situations: Upstream code producing zero documents (empty query, failed file/chunk parsing); building the request conditionally without checking size; framework batchers passing empty batches.
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
- No embedding input is provided - all texts are null or empty
- ImagePrompt must contain at least one non-empty message
- model cannot be null or empty
- think level must be one of
- SSE connection '<connectionName>' requires a 'url' property.
AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11).
Data as JSON: /api/errors/3872761ca013f5b0.
Report an issue: GitHub.