{"record":{"id":"59f07728f6ada151","repo":"spring-projects/spring-ai","slug":"no-chat-completion-returned-for-prompt-prompt-59f077","errorCode":null,"errorMessage":"No chat completion returned for prompt: + prompt","messagePattern":"No chat completion returned for prompt: \\+ prompt","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/MistralAiChatModel.java","lineNumber":196,"sourceCode":"\n\t\tChatModelObservationContext observationContext = ChatModelObservationContext.builder()\n\t\t\t.prompt(prompt)\n\t\t\t.provider(MistralAiApi.PROVIDER_NAME)\n\t\t\t.build();\n\n\t\tChatResponse response = ChatModelObservationDocumentation.CHAT_MODEL_OPERATION\n\t\t\t.observation(this.observationConvention, DEFAULT_OBSERVATION_CONVENTION, () -> observationContext,\n\t\t\t\t\tthis.observationRegistry)\n\t\t\t.observe(() -> {\n\n\t\t\t\tResponseEntity<ChatCompletion> completionEntity = RetryUtils.execute(this.retryTemplate,\n\t\t\t\t\t\t() -> this.mistralAiApi.chatCompletionEntity(request));\n\n\t\t\t\tChatCompletion chatCompletion = completionEntity.getBody();\n\n\t\t\t\tif (chatCompletion == null) {\n\t\t\t\t\tif (logger.isWarnEnabled()) {\n\t\t\t\t\t\tlogger.warn(\"No chat completion returned for prompt: \" + prompt);\n\t\t\t\t\t}\n\t\t\t\t\treturn new ChatResponse(List.of());\n\t\t\t\t}\n\n\t\t\t\tList<Generation> generations = chatCompletion.choices().stream().map(choice -> {\n\t\t\t\t\tvar role = choice.message().role() != null ? choice.message().role().name() : \"\";\n\t\t\t\t\tvar metadata = buildMetadata(choice, chatCompletion.id(), role);\n\n\t\t\t\t\treturn buildGeneration(choice, metadata);\n\t\t\t\t}).toList();\n\n\t\t\t\tChatCompletion completion = Objects.requireNonNull(completionEntity.getBody());\n\t\t\t\tvar usage = Objects.requireNonNull(completion.usage());\n\t\t\t\tDefaultUsage defaultUsage = getDefaultUsage(usage);\n\t\t\t\tUsage cumulativeUsage = UsageCalculator.getCumulativeUsage(defaultUsage, previousChatResponse);\n\t\t\t\tChatResponse chatResponse = new ChatResponse(generations,\n\t\t\t\t\t\tfrom(completionEntity.getBody(), cumulativeUsage));\n","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/MistralAiChatModel.java#L178-L214","documentation":"Warning logged by MistralAiChatModel.internalCall() when the ResponseEntity body from mistralAiApi.chatCompletionEntity() is null — Mistral returned no ChatCompletion object. The model returns an empty ChatResponse (empty generations) instead of throwing, so downstream code sees an apparently valid but content-less response.","triggerScenarios":"mistralAiApi.chatCompletionEntity(request) completes within RetryUtils but completionEntity.getBody() == null — empty HTTP body from the Mistral API or an unparseable payload.","commonSituations":"Invalid Mistral API key or exhausted rate limit returning an unexpected empty response; Mistral platform incidents; self-hosted/proxied endpoints (custom baseUrl) that return empty bodies; contract drift after Mistral API updates.","solutions":["Verify MISTRAL_AI_API_KEY validity and account/quota status.","Log the raw HTTP exchange (interceptor on RestClient) to see the actual status/body.","Check spring-ai-mistral-ai and Mistral API version compatibility.","Guard callers against empty ChatResponse.getResults() before accessing generations."],"exampleFix":"// before\nChatResponse r = mistralChatModel.call(new Prompt(prompt));\nString answer = r.getResult().getOutput().getText();\n// after\nString answer = r.getResults().isEmpty() ? fallbackAnswer : r.getResult().getOutput().getText();","handlingStrategy":"try-catch","validationCode":"Assert.hasText(mistralApiKey, \"MISTRAL_AI_API_KEY must be set\");","typeGuard":"static boolean isEmpty(ChatResponse r) { return r == null || r.getResults() == null || r.getResults().isEmpty(); }","tryCatchPattern":"ChatResponse r = mistralChatModel.call(new Prompt(prompt));\nif (isEmpty(r)) { log.error(\"Mistral returned no completion\"); return retryOrFallback(); }","preventionTips":["Verify API key and rate limits before deployments","Log raw HTTP exchanges to distinguish empty-body success from auth failures","Keep spring-ai-mistral-ai in sync with Mistral API changes"],"tags":["mistral","chat-completion","null-response","http"],"backgroundTag":"empty-response-body","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"}