Skip to content

Commit 70e2dba

Browse files
Better error messages
1 parent eb1f19d commit 70e2dba

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationChatResponse.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,23 @@ public LLMChoice getChoice() {
122122
*/
123123
@Nonnull
124124
public <T> T entity(@Nonnull final Class<T> type) {
125+
String refusal =
126+
((LLMModuleResultSynchronous) getOriginalResponse().getOrchestrationResult())
127+
.getChoices()
128+
.get(0)
129+
.getMessage()
130+
.getRefusal();
131+
if (refusal != null) {
132+
throw new OrchestrationClientException(
133+
"The model refused to answer the question: " + refusal);
134+
}
125135
try {
126136
return new ObjectMapper().readValue(getContent(), type);
127137
} catch (JsonProcessingException e) {
128138
throw new OrchestrationClientException(
129-
"Failed to deserialize the JSON content: " + e.getMessage(), e);
139+
"Failed to deserialize the JSON content, please configure an OrchestrationTemplate with format set to JSON schema into your OrchestrationModuleConfig"
140+
+ e.getMessage(),
141+
e);
130142
}
131143
}
132144
}

0 commit comments

Comments
 (0)