spring-projects/spring-ai · warning
ChatClientResponse is missing required json output for valid
Error message
ChatClientResponse is missing required json output for validation.
What it means
StructuredOutputValidationAdvisor.validateOutputSchema extracts the JSON text from the ChatClientResponse for schema validation. If the response, its ChatResponse, its single result, or the output text is null, there is nothing to validate, so it logs a warning and returns SchemaValidation.failed — which drives the retry/error path instead of throwing a NPE.
Source
Thrown at spring-ai-client-chat/src/main/java/org/springframework/ai/chat/client/advisor/StructuredOutputValidationAdvisor.java:184
.build());
processedChatClientRequest = chatClientRequest.mutate().prompt(augmentedPrompt).build();
}
else if (logger.isDebugEnabled()) {
logger.debug("JSON validation succeeded");
}
}
}
return usageAccumulator.applyAccumulatedUsage(Objects.requireNonNull(chatClientResponse));
}
private SchemaValidation validateOutputSchema(ChatClientResponse chatClientResponse, int leftAttemptsCounter) {
if (chatClientResponse.chatResponse() == null || chatClientResponse.chatResponse().getResult() == null
|| chatClientResponse.chatResponse().getResult().getOutput().getText() == null) {
logger.warn("ChatClientResponse is missing required json output for validation.");
return SchemaValidation.failed("Missing required json output for validation.");
}
// TODO: should we consider validation for multiple results?
String json = chatClientResponse.chatResponse().getResult().getOutput().getText();
if (logger.isDebugEnabled()) {
logger.debug("Validating JSON output against schema. Attempts left: " + leftAttemptsCounter);
}
return validateJsonText(json);
}
private SchemaValidation validateJsonText(String json) {
if (json.isBlank()) {
return SchemaValidation.failed("Empty JSON output for validation.");
}
try {View on GitHub (pinned to 98a7beda4f)
Solutions
- Check why the ChatResponse/text is empty — often the model returned no choices (enable DEBUG logging, inspect the raw API response)
- Ensure the advisor runs on a normal chat completion flow that produces text output
- Rephrase the prompt or check content filtering if the model returns an empty completion
- Handle SchemaValidation failure in the response flow and retry the request
Example fix
// before
String json = response.chatResponse().getResult().getOutput().getText();
validate(json);
// after
ChatResponse cr = response.chatResponse();
if (cr == null || cr.getResult() == null || cr.getResult().getOutput().getText() == null) {
throw new IllegalStateException("Model produced no text to validate");
} Defensive patterns
Strategy: type-guard
Validate before calling
ChatResponse cr = response.chatResponse();
String json = (cr != null && cr.getResult() != null && cr.getResult().getOutput() != null)
? cr.getResult().getOutput().getText() : null;
if (json == null || json.isBlank()) throw new IllegalStateException("no text output"); Type guard
static boolean hasValidatableText(ChatClientResponse r) {
return r != null && r.chatResponse() != null && r.chatResponse().getResult() != null
&& r.chatResponse().getResult().getOutput() != null
&& r.chatResponse().getResult().getOutput().getText() != null;
} Prevention
- Ensure the model call actually returns text before applying the advisor
- Investigate empty-choice responses upstream
- Don't apply the advisor to calls that short-circuit without a ChatResponse
When it happens
Trigger: Calling through the advisor pipeline when the model call produced no ChatResponse or produced a generation whose output has no text — e.g. empty completion (see empty-choices case), streamed empty response, or an error short-circuit in the chain.
Common situations: Upstream model returning empty results (content filter, proxy issue); the advisor applied to a call that didn't produce assistant text; misconfigured chain where the ChatResponse was never set.
Related errors
- JSON validation failed: ${validationResponse}
- Failed to parse JSON schema:
- Failed to parse JSON schema
- Only outputType or outputJsonSchema can be set, not both.
- Either outputType or outputJsonSchema must be set.
AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11).
Data as JSON: /api/errors/e0ab97577581d554.
Report an issue: GitHub.