spring-projects/spring-ai · warning
No chat completion returned for prompt: + prompt
Error message
No chat completion returned for prompt: + prompt
What it means
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.
Source
Thrown at models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/MistralAiChatModel.java:196
ChatModelObservationContext observationContext = ChatModelObservationContext.builder()
.prompt(prompt)
.provider(MistralAiApi.PROVIDER_NAME)
.build();
ChatResponse response = ChatModelObservationDocumentation.CHAT_MODEL_OPERATION
.observation(this.observationConvention, DEFAULT_OBSERVATION_CONVENTION, () -> observationContext,
this.observationRegistry)
.observe(() -> {
ResponseEntity<ChatCompletion> completionEntity = RetryUtils.execute(this.retryTemplate,
() -> this.mistralAiApi.chatCompletionEntity(request));
ChatCompletion chatCompletion = completionEntity.getBody();
if (chatCompletion == null) {
if (logger.isWarnEnabled()) {
logger.warn("No chat completion returned for prompt: " + prompt);
}
return new ChatResponse(List.of());
}
List<Generation> generations = chatCompletion.choices().stream().map(choice -> {
var role = choice.message().role() != null ? choice.message().role().name() : "";
var metadata = buildMetadata(choice, chatCompletion.id(), role);
return buildGeneration(choice, metadata);
}).toList();
ChatCompletion completion = Objects.requireNonNull(completionEntity.getBody());
var usage = Objects.requireNonNull(completion.usage());
DefaultUsage defaultUsage = getDefaultUsage(usage);
Usage cumulativeUsage = UsageCalculator.getCumulativeUsage(defaultUsage, previousChatResponse);
ChatResponse chatResponse = new ChatResponse(generations,
from(completionEntity.getBody(), cumulativeUsage));
View on GitHub (pinned to 98a7beda4f)
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.
Example fix
// before ChatResponse r = mistralChatModel.call(new Prompt(prompt)); String answer = r.getResult().getOutput().getText(); // after String answer = r.getResults().isEmpty() ? fallbackAnswer : r.getResult().getOutput().getText();
Defensive patterns
Strategy: try-catch
Validate before calling
Assert.hasText(mistralApiKey, "MISTRAL_AI_API_KEY must be set");
Type guard
static boolean isEmpty(ChatResponse r) { return r == null || r.getResults() == null || r.getResults().isEmpty(); } Try / catch
ChatResponse r = mistralChatModel.call(new Prompt(prompt));
if (isEmpty(r)) { log.error("Mistral returned no completion"); return retryOrFallback(); } Prevention
- 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
When it happens
Trigger: mistralAiApi.chatCompletionEntity(request) completes within RetryUtils but completionEntity.getBody() == null — empty HTTP body from the Mistral API or an unparseable payload.
Common situations: 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.
Related errors
- No chat completion returned for prompt: + prompt
- No embeddings returned for request: + request
- No moderation response returned for request: + mistralAiMode
- HTTP %s - %s
- Stateless Streamable-Http prompt method must not declare par
AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11).
Data as JSON: /api/errors/59f07728f6ada151.
Report an issue: GitHub.