{"record":{"id":"3872761ca013f5b0","repo":"spring-projects/spring-ai","slug":"no-embedding-input-is-provided-instructions-list","errorCode":null,"errorMessage":"No embedding input is provided - instructions list is empty","messagePattern":"No embedding input is provided - instructions list is empty","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"models/spring-ai-google-genai-embedding/src/main/java/org/springframework/ai/google/genai/text/GoogleGenAiTextEmbeddingModel.java","lineNumber":165,"sourceCode":"\t\t\t\tEmbedContentConfig.Builder configBuilder = EmbedContentConfig.builder();\n\n\t\t\t\t// Set dimensions if specified\n\t\t\t\tif (options.getDimensions() != null) {\n\t\t\t\t\tconfigBuilder.outputDimensionality(options.getDimensions());\n\t\t\t\t}\n\n\t\t\t\t// Set task type if specified - this might need to be handled differently\n\t\t\t\t// as the new SDK might not have a direct taskType field\n\t\t\t\t// We'll need to check the SDK documentation for this\n\n\t\t\t\tEmbedContentConfig config = configBuilder.build();\n\n\t\t\t\t// Convert instructions to Content list for embedding\n\t\t\t\tList<String> texts = embeddingRequest.getInstructions();\n\n\t\t\t\t// Validate that we have texts to embed\n\t\t\t\tif (texts == null || texts.isEmpty()) {\n\t\t\t\t\tthrow new IllegalArgumentException(\"No embedding input is provided - instructions list is empty\");\n\t\t\t\t}\n\n\t\t\t\t// Filter out null or empty strings\n\t\t\t\tList<String> validTexts = texts.stream().filter(StringUtils::hasText).toList();\n\n\t\t\t\tif (validTexts.isEmpty()) {\n\t\t\t\t\tthrow new IllegalArgumentException(\"No embedding input is provided - all texts are null or empty\");\n\t\t\t\t}\n\n\t\t\t\t// Call the embedding API with retry\n\t\t\t\tEmbedContentResponse embeddingResponse = RetryUtils.execute(this.retryTemplate,\n\t\t\t\t\t\t() -> this.genAiClient.models.embedContent(modelName, validTexts, config));\n\n\t\t\t\t// Process the response\n\t\t\t\t// Note: We need to handle the case where some texts were filtered out\n\t\t\t\t// The response will only contain embeddings for valid texts\n\t\t\t\tint totalTokenCount = 0;\n\t\t\t\tList<Embedding> embeddingList = new ArrayList<>();","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/models/spring-ai-google-genai-embedding/src/main/java/org/springframework/ai/google/genai/text/GoogleGenAiTextEmbeddingModel.java#L147-L183","documentation":"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.","triggerScenarios":"Calling embed()/call() with an EmbeddingRequest constructed with an empty list of instructions or null instructions.","commonSituations":"Upstream code producing zero documents (empty query, failed file/chunk parsing); building the request conditionally without checking size; framework batchers passing empty batches.","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)"],"exampleFix":"// before\nEmbeddingRequest req = new EmbeddingRequest(List.of(), EmbeddingOptionsBuilder.builder().build());\nmodel.embed(req); // throws\n// after\nif (!texts.isEmpty()) {\n    EmbeddingRequest req = new EmbeddingRequest(texts, EmbeddingOptionsBuilder.builder().build());\n    model.embed(req);\n}","handlingStrategy":"validation","validationCode":"List<String> texts = embeddingRequest.getInstructions();\nif (texts == null || texts.isEmpty()) {\n    throw new IllegalArgumentException(\"EmbeddingRequest must contain at least one instruction\");\n}","typeGuard":"boolean hasEmbeddingInput(EmbeddingRequest req) { return req.getInstructions() != null && !req.getInstructions().isEmpty(); }","tryCatchPattern":"try { model.embed(request); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"instructions list is empty\")) { return EmbeddingResponse.empty(); } throw e; }","preventionTips":["Check batch/document lists for emptiness before embedding","Ensure upstream chunking/parsing actually yields content","Guard conditional request-building code paths"],"tags":["google-genai","embeddings","validation","illegal-argument"],"backgroundTag":"empty-required-field","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}