spring-projects/spring-ai · warning
Query translation result is null/empty. Returning the input…
Error message
Query translation result is null/empty. Returning the input query unchanged.
What it means
TranslationQueryTransformer asks a ChatModel to translate the query into a target language. If the model returns null or blank text, the transformer logs this warning and falls back to the original untranslated query so retrieval still proceeds. It signals the translation step silently failed.
Solutions
- Verify the ChatModel actually returns content for this language; test the prompt manually outside the transformer.
- Use a model with solid multilingual capability for the targetLanguage.
- Increase maxTokens / adjust the translation prompt to forbid empty output or meta commentary.
- Accept the fallback — the original query is returned, but expect degraded retrieval quality in the target language.
Example fix
// before
QueryTransformer t = TranslationQueryTransformer.builder()
.chatClientBuilder(clientBuilder)
.targetLanguage("xx") // obscure/unsupported language
.build();
// after
QueryTransformer t = TranslationQueryTransformer.builder()
.chatClientBuilder(multilingualModelClientBuilder)
.targetLanguage("fr")
.build(); Defensive patterns
Strategy: validation
Validate before calling
if (query != null && StringUtils.hasText(query.text()) && targetLanguage != null && !targetLanguage.isBlank()) {
// proceed with translation; empty results fall back to original query
} Prevention
- Pick models with proven multilingual output for your target languages.
- Write translation prompts that forbid empty or meta responses.
- Smoke-test each targetLanguage against the model before rollout.
- Beware content filters emptying responses on certain inputs.
When it happens
Trigger: Calling transform(Query) with a targetLanguage whose model call yields null/blank content — e.g. unsupported target language confuses the model, content filter blocks the response, empty completion, or provider returns no content.
Common situations: Translating into less common languages with weak models; content filters (Azure OpenAI) emptying the response; maxTokens too low; provider outage; asking a model that only answers in the source language so it outputs nothing meaningful — or the model echoing, which is handled elsewhere.
Understand the failure class
Background: "empty response", "returned no data", "empty embeddings": what HTTP 200-with-empty-body errors mean across libraries — this error's family across 36 libraries.
Related errors
- Query rewrite result is null/empty. Returning the input…
- Empty embedding vector returned for input at index +…
- Failed to parse metadata JSON. Using empty metadata. json=
- Image generation failed: no image returned
- keywordCount will be ignored as keywordsTemplate is set.
AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11).
Data as JSON: /api/errors/f2466332dc73101f.
Report an issue: GitHub.
Appendix: source
Thrown at spring-ai-rag/src/main/java/org/springframework/ai/rag/preretrieval/query/transformation/TranslationQueryTransformer.java:99
}
@Override
public Query transform(Query query) {
Assert.notNull(query, "query cannot be null");
if (logger.isDebugEnabled()) {
logger.debug("Translating query to target language: " + this.targetLanguage);
}
var translatedQueryText = this.chatClient.prompt()
.user(user -> user.text(this.promptTemplate.getTemplate())
.param("targetLanguage", this.targetLanguage)
.param("query", query.text()))
.call()
.content();
if (!StringUtils.hasText(translatedQueryText)) {
logger.warn("Query translation result is null/empty. Returning the input query unchanged.");
return query;
}
return query.mutate().text(translatedQueryText).build();
}
public static Builder builder() {
return new Builder();
}
public static final class Builder {
private ChatClient.@Nullable Builder chatClientBuilder;
private @Nullable PromptTemplate promptTemplate;
private @Nullable String targetLanguage;
View on GitHub (pinned to 98a7beda4f)