diff --git a/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/response/ErrorItem.java b/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/response/ErrorItem.java
index ddd24de3..37ef7c88 100644
--- a/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/response/ErrorItem.java
+++ b/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/response/ErrorItem.java
@@ -1,8 +1,12 @@
package ai.docling.serve.api.convert.response;
+import org.jspecify.annotations.Nullable;
+
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
+import ai.docling.serve.api.task.response.FailureCategory;
+
/**
* Represents an individual error produced during document conversion.
*
@@ -42,6 +46,28 @@ public class ErrorItem {
@JsonProperty("module_name")
private String moduleName;
+ /**
+ * Semantic category of the error, for filtering.
+ *
+ *
Absent from responses produced by Docling Serve versions predating this field.
+ *
+ * @param category the error category, or null if not reported
+ * @return the error category, or null if not reported
+ */
+ @JsonProperty("category")
+ @Nullable
+ private FailureCategory category;
+
+ /**
+ * 1-indexed page the error is attributable to, or null for document-scoped errors.
+ *
+ * @param pageNo the page number, or null if not applicable
+ * @return the page number, or null if not applicable
+ */
+ @JsonProperty("page_no")
+ @Nullable
+ private Integer pageNo;
+
/**
* Builder for creating {@link ErrorItem} instances.
* Generated by Lombok's {@code @Builder} annotation.
@@ -51,6 +77,8 @@ public class ErrorItem {
*
{@code componentType(String)} - Set the component type
* {@code errorMessage(String)} - Set the error message
* {@code moduleName(String)} - Set the module name
+ * {@code category(FailureCategory)} - Set the error category
+ * {@code pageNo(Integer)} - Set the page number
*
*/
public static class Builder {
diff --git a/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/task/response/FailureCategory.java b/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/task/response/FailureCategory.java
new file mode 100644
index 00000000..c3eb8d8e
--- /dev/null
+++ b/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/task/response/FailureCategory.java
@@ -0,0 +1,49 @@
+package ai.docling.serve.api.task.response;
+
+import com.fasterxml.jackson.annotation.JsonEnumDefaultValue;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+/**
+ * Semantic category of a task or document failure reported by Docling Serve.
+ *
+ * Shared by {@link TaskFailureInfo} (task scope) and document/page-scope errors.
+ * Upstream documents this category as extensible, so {@link #UNKNOWN} is also the
+ * default value used when an unrecognized category is encountered during
+ * deserialization. This graceful fallback is enabled by default on the JSON mappers
+ * used by {@code docling-serve-client}; a consumer supplying its own Jackson 2 or
+ * Jackson 3 mapper must enable the equivalent "read unknown enum as default" feature
+ * itself to get the same behavior instead of a hard deserialization failure.
+ *
+ *
+ * - {@code POLICY}: The request violated a service policy (e.g. an unreachable or disallowed source).
+ * - {@code CAPACITY}: The service ran out of capacity while processing the task.
+ * - {@code SOURCE_UNAVAILABLE}: The source document could not be reached.
+ * - {@code TARGET_UNAVAILABLE}: The result could not be written to the requested target.
+ * - {@code TIMEOUT}: The task exceeded the allowed execution time.
+ * - {@code INTERNAL}: An internal service defect caused the failure.
+ * - {@code BACKEND_FAILURE}: A document/page-scope backend processing failure.
+ * - {@code INFERENCE_FAILURE}: A document/page-scope model inference failure.
+ * - {@code UNKNOWN}: The failure could not be categorized, including categories unrecognized by this version of the library.
+ *
+ */
+public enum FailureCategory {
+ @JsonProperty("policy")
+ POLICY,
+ @JsonProperty("capacity")
+ CAPACITY,
+ @JsonProperty("source_unavailable")
+ SOURCE_UNAVAILABLE,
+ @JsonProperty("target_unavailable")
+ TARGET_UNAVAILABLE,
+ @JsonProperty("timeout")
+ TIMEOUT,
+ @JsonProperty("internal")
+ INTERNAL,
+ @JsonProperty("backend_failure")
+ BACKEND_FAILURE,
+ @JsonProperty("inference_failure")
+ INFERENCE_FAILURE,
+ @JsonProperty("unknown")
+ @JsonEnumDefaultValue
+ UNKNOWN;
+}
diff --git a/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/task/response/FailurePhase.java b/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/task/response/FailurePhase.java
new file mode 100644
index 00000000..8be7b30f
--- /dev/null
+++ b/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/task/response/FailurePhase.java
@@ -0,0 +1,30 @@
+package ai.docling.serve.api.task.response;
+
+import com.fasterxml.jackson.annotation.JsonEnumDefaultValue;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+/**
+ * Processing phase in which a task failure occurred, as reported in {@link TaskFailureInfo}.
+ *
+ *
+ * - {@code ADMISSION}: The failure occurred while admitting the task (e.g. a document exceeded service limits).
+ * - {@code SOURCE_ENUMERATION}: The failure occurred while resolving or fetching the source document.
+ * - {@code EXECUTION}: The failure occurred while executing the conversion pipeline.
+ * - {@code ORCHESTRATION}: The failure occurred in task orchestration, outside a specific document-processing phase.
+ * - {@code UNKNOWN}: The phase could not be determined. Not an upstream value; added by this library as a
+ * forward-compatibility fallback for phases unrecognized by this version of the library.
+ *
+ */
+public enum FailurePhase {
+ @JsonProperty("admission")
+ ADMISSION,
+ @JsonProperty("source_enumeration")
+ SOURCE_ENUMERATION,
+ @JsonProperty("execution")
+ EXECUTION,
+ @JsonProperty("orchestration")
+ ORCHESTRATION,
+ @JsonProperty("unknown")
+ @JsonEnumDefaultValue
+ UNKNOWN;
+}
diff --git a/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/task/response/TaskFailureInfo.java b/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/task/response/TaskFailureInfo.java
new file mode 100644
index 00000000..82267e45
--- /dev/null
+++ b/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/task/response/TaskFailureInfo.java
@@ -0,0 +1,85 @@
+package ai.docling.serve.api.task.response;
+
+import java.util.Map;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+/**
+ * Structured failure information reported by Docling Serve for a failed task.
+ *
+ * Only populated when the backing Docling Serve deployment uses the Ray orchestrator
+ * (available since Docling Serve v1.25.0); other orchestrators report only
+ * {@link TaskStatusPollResponse#getErrorMessage()}.
+ *
+ *
Serialization uses {@link JsonInclude.Include#NON_EMPTY}, so nulls and empty
+ * collections are omitted from JSON output.
+ */
+@JsonInclude(JsonInclude.Include.NON_EMPTY)
+@lombok.extern.jackson.Jacksonized
+@lombok.Builder(toBuilder = true)
+@lombok.Getter
+@lombok.ToString
+public class TaskFailureInfo {
+ /**
+ * Semantic category of the failure.
+ *
+ * @param category the failure category
+ * @return the failure category
+ */
+ @JsonProperty("category")
+ private FailureCategory category;
+
+ /**
+ * Human-readable description of the failure, more specific than the task's
+ * generic error message for the same failure.
+ *
+ * @param message the failure message
+ * @return the failure message
+ */
+ @JsonProperty("message")
+ private String message;
+
+ /**
+ * Whether the task can be resubmitted with a reasonable chance of success.
+ *
+ * @param retryable whether the failure is retryable
+ * @return whether the failure is retryable
+ */
+ @JsonProperty("retryable")
+ private boolean retryable;
+
+ /**
+ * Processing phase in which the failure occurred.
+ *
+ * @param phase the failure phase
+ * @return the failure phase
+ */
+ @JsonProperty("phase")
+ private FailurePhase phase;
+
+ /**
+ * Additional structured details about the failure.
+ *
+ * @param details the failure details, keyed by detail name
+ * @return the failure details, keyed by detail name
+ */
+ @JsonProperty("details")
+ private Map details;
+
+ /**
+ * Builder for creating {@link TaskFailureInfo} instances.
+ * Generated by Lombok's {@code @Builder} annotation.
+ *
+ * Builder methods:
+ *
+ * - {@code category(FailureCategory)} - Set the failure category
+ * - {@code message(String)} - Set the failure message
+ * - {@code retryable(boolean)} - Set whether the failure is retryable
+ * - {@code phase(FailurePhase)} - Set the failure phase
+ * - {@code details(Map)} - Set the failure details
+ *
+ */
+ public static class Builder {
+ }
+}
diff --git a/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/task/response/TaskStatusMetadata.java b/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/task/response/TaskStatusMetadata.java
index a3aa626f..43a1abdf 100644
--- a/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/task/response/TaskStatusMetadata.java
+++ b/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/task/response/TaskStatusMetadata.java
@@ -1,5 +1,7 @@
package ai.docling.serve.api.task.response;
+import org.jspecify.annotations.Nullable;
+
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
@@ -21,6 +23,7 @@
* - {@code numDocs}: The total number of documents associated with the task.
* - {@code numProcessed}: The number of documents that have been processed.
* - {@code numSucceeded}: The number of documents that were successfully processed.
+ * - {@code numPartiallySucceeded}: The number of documents that were partially processed successfully.
* - {@code numFailed}: The number of documents that failed processing.
*/
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@@ -32,37 +35,53 @@ public class TaskStatusMetadata {
/**
* Total number of documents in the task.
*
- * @param numDocs the total number of documents
- * @return the total number of documents
+ * @param numDocs the total number of documents, or null if not reported
+ * @return the total number of documents, or null if not reported
*/
@JsonProperty("num_docs")
+ @Nullable
private Long numDocs;
/**
* Number of documents processed so far.
*
- * @param numProcessed the number of processed documents
- * @return the number of processed documents
+ * @param numProcessed the number of processed documents, or null if not reported
+ * @return the number of processed documents, or null if not reported
*/
@JsonProperty("num_processed")
+ @Nullable
private Long numProcessed;
/**
* Number of documents that succeeded.
*
- * @param numSucceeded the number of successful documents
- * @return the number of successful documents
+ * @param numSucceeded the number of successful documents, or null if not reported
+ * @return the number of successful documents, or null if not reported
*/
@JsonProperty("num_succeeded")
+ @Nullable
private Long numSucceeded;
+ /**
+ * Number of documents that were partially processed successfully.
+ *
+ * Absent from responses produced by Docling Serve versions predating this field.
+ *
+ * @param numPartiallySucceeded the number of partially successful documents, or null if not reported
+ * @return the number of partially successful documents, or null if not reported
+ */
+ @JsonProperty("num_partially_succeeded")
+ @Nullable
+ private Long numPartiallySucceeded;
+
/**
* Number of documents that failed.
*
- * @param numFailed the number of failed documents
- * @return the number of failed documents
+ * @param numFailed the number of failed documents, or null if not reported
+ * @return the number of failed documents, or null if not reported
*/
@JsonProperty("num_failed")
+ @Nullable
private Long numFailed;
/**
@@ -74,6 +93,7 @@ public class TaskStatusMetadata {
*
{@code numDocs(Long)} - Set the total number of documents
* {@code numProcessed(Long)} - Set the number of processed documents
* {@code numSucceeded(Long)} - Set the number of successful documents
+ * {@code numPartiallySucceeded(Long)} - Set the number of partially successful documents
* {@code numFailed(Long)} - Set the number of failed documents
*
*/
diff --git a/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/task/response/TaskStatusPollResponse.java b/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/task/response/TaskStatusPollResponse.java
index 797a74a4..2f7ba7ea 100644
--- a/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/task/response/TaskStatusPollResponse.java
+++ b/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/task/response/TaskStatusPollResponse.java
@@ -25,6 +25,7 @@
* - {@code taskPosition}: A numerical representation of the task's position in the processing queue.
* - {@code taskStatusMetadata}: Metadata providing detailed statistics and progress information (optional).
* - {@code errorMessage}: The error message reported by Docling Serve when the task failed (optional).
+ * - {@code failure}: Structured failure information reported by Docling Serve when the task failed (optional).
*/
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@lombok.extern.jackson.Jacksonized
@@ -90,6 +91,19 @@ public class TaskStatusPollResponse {
@Nullable
private String errorMessage;
+ /**
+ * Structured failure information reported by Docling Serve when the task failed.
+ *
+ * Only populated by deployments using the Ray orchestrator; other orchestrators
+ * report only {@link #getErrorMessage()}.
+ *
+ * @param failure the structured failure information, or null if not available
+ * @return the structured failure information, or null if not available
+ */
+ @JsonProperty("failure")
+ @Nullable
+ private TaskFailureInfo failure;
+
/**
* Builder for creating {@link TaskStatusPollResponse} instances.
* Generated by Lombok's {@code @Builder} annotation.
@@ -102,6 +116,7 @@ public class TaskStatusPollResponse {
*
{@code taskPosition(Long)} - Set the queue position
* {@code taskStatusMetadata(TaskStatusMetadata)} - Set the task metadata
* {@code errorMessage(String)} - Set the error message
+ * {@code failure(TaskFailureInfo)} - Set the structured failure information
*
*/
public static class Builder {
diff --git a/docling-serve/docling-serve-api/src/test/java/ai/docling/serve/api/convert/response/ErrorItemTests.java b/docling-serve/docling-serve-api/src/test/java/ai/docling/serve/api/convert/response/ErrorItemTests.java
index cbbd9337..78c4aa1f 100644
--- a/docling-serve/docling-serve-api/src/test/java/ai/docling/serve/api/convert/response/ErrorItemTests.java
+++ b/docling-serve/docling-serve-api/src/test/java/ai/docling/serve/api/convert/response/ErrorItemTests.java
@@ -4,6 +4,8 @@
import org.junit.jupiter.api.Test;
+import ai.docling.serve.api.task.response.FailureCategory;
+
/**
* Unit tests for {@link ErrorItem}.
*/
@@ -14,16 +16,22 @@ void createErrorItemWithAllFields() {
String componentType = "parser";
String errorMessage = "Failed to parse document structure";
String moduleName = "docling.core.parser";
+ FailureCategory category = FailureCategory.BACKEND_FAILURE;
+ Integer pageNo = 3;
ErrorItem errorItem = ErrorItem.builder()
.componentType(componentType)
.errorMessage(errorMessage)
.moduleName(moduleName)
+ .category(category)
+ .pageNo(pageNo)
.build();
assertThat(errorItem.getComponentType()).isEqualTo(componentType);
assertThat(errorItem.getErrorMessage()).isEqualTo(errorMessage);
assertThat(errorItem.getModuleName()).isEqualTo(moduleName);
+ assertThat(errorItem.getCategory()).isEqualTo(category);
+ assertThat(errorItem.getPageNo()).isEqualTo(pageNo);
}
@Test
@@ -33,6 +41,8 @@ void createErrorItemWithNullFields() {
assertThat(errorItem.getComponentType()).isNull();
assertThat(errorItem.getErrorMessage()).isNull();
assertThat(errorItem.getModuleName()).isNull();
+ assertThat(errorItem.getCategory()).isNull();
+ assertThat(errorItem.getPageNo()).isNull();
}
@Test
diff --git a/docling-serve/docling-serve-api/src/test/java/ai/docling/serve/api/task/response/TaskFailureInfoTests.java b/docling-serve/docling-serve-api/src/test/java/ai/docling/serve/api/task/response/TaskFailureInfoTests.java
new file mode 100644
index 00000000..0eb971ec
--- /dev/null
+++ b/docling-serve/docling-serve-api/src/test/java/ai/docling/serve/api/task/response/TaskFailureInfoTests.java
@@ -0,0 +1,56 @@
+package ai.docling.serve.api.task.response;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Map;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * Unit tests for {@link TaskFailureInfo}.
+ */
+class TaskFailureInfoTests {
+
+ @Test
+ void createTaskFailureInfoWithAllFields() {
+ FailureCategory category = FailureCategory.TIMEOUT;
+ String message = "Task exceeded the allowed execution time.";
+ FailurePhase phase = FailurePhase.EXECUTION;
+ Map details = Map.of("timeout_class", "TimeoutError");
+
+ TaskFailureInfo failure = TaskFailureInfo.builder()
+ .category(category)
+ .message(message)
+ .retryable(true)
+ .phase(phase)
+ .details(details)
+ .build();
+
+ assertThat(failure.getCategory()).isEqualTo(category);
+ assertThat(failure.getMessage()).isEqualTo(message);
+ assertThat(failure.isRetryable()).isTrue();
+ assertThat(failure.getPhase()).isEqualTo(phase);
+ assertThat(failure.getDetails()).isEqualTo(details);
+ }
+
+ @Test
+ void createTaskFailureInfoWithNullFields() {
+ TaskFailureInfo failure = TaskFailureInfo.builder().build();
+
+ assertThat(failure.getCategory()).isNull();
+ assertThat(failure.getMessage()).isNull();
+ assertThat(failure.isRetryable()).isFalse();
+ assertThat(failure.getPhase()).isNull();
+ assertThat(failure.getDetails()).isNull();
+ }
+
+ @Test
+ void createTaskFailureInfoWithEmptyDetails() {
+ TaskFailureInfo failure = TaskFailureInfo.builder()
+ .details(Map.of())
+ .build();
+
+ assertThat(failure.getDetails()).isEmpty();
+ }
+
+}
diff --git a/docling-serve/docling-serve-api/src/test/java/ai/docling/serve/api/task/response/TaskStatusMetadataTests.java b/docling-serve/docling-serve-api/src/test/java/ai/docling/serve/api/task/response/TaskStatusMetadataTests.java
new file mode 100644
index 00000000..eab0e275
--- /dev/null
+++ b/docling-serve/docling-serve-api/src/test/java/ai/docling/serve/api/task/response/TaskStatusMetadataTests.java
@@ -0,0 +1,40 @@
+package ai.docling.serve.api.task.response;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * Unit tests for {@link TaskStatusMetadata}.
+ */
+class TaskStatusMetadataTests {
+
+ @Test
+ void createTaskStatusMetadataWithAllFields() {
+ TaskStatusMetadata metadata = TaskStatusMetadata.builder()
+ .numDocs(10L)
+ .numProcessed(8L)
+ .numSucceeded(5L)
+ .numPartiallySucceeded(2L)
+ .numFailed(1L)
+ .build();
+
+ assertThat(metadata.getNumDocs()).isEqualTo(10L);
+ assertThat(metadata.getNumProcessed()).isEqualTo(8L);
+ assertThat(metadata.getNumSucceeded()).isEqualTo(5L);
+ assertThat(metadata.getNumPartiallySucceeded()).isEqualTo(2L);
+ assertThat(metadata.getNumFailed()).isEqualTo(1L);
+ }
+
+ @Test
+ void createTaskStatusMetadataWithNullFields() {
+ TaskStatusMetadata metadata = TaskStatusMetadata.builder().build();
+
+ assertThat(metadata.getNumDocs()).isNull();
+ assertThat(metadata.getNumProcessed()).isNull();
+ assertThat(metadata.getNumSucceeded()).isNull();
+ assertThat(metadata.getNumPartiallySucceeded()).isNull();
+ assertThat(metadata.getNumFailed()).isNull();
+ }
+
+}
diff --git a/docling-serve/docling-serve-api/src/test/java/ai/docling/serve/api/task/response/TaskStatusPollResponseTests.java b/docling-serve/docling-serve-api/src/test/java/ai/docling/serve/api/task/response/TaskStatusPollResponseTests.java
new file mode 100644
index 00000000..7e531309
--- /dev/null
+++ b/docling-serve/docling-serve-api/src/test/java/ai/docling/serve/api/task/response/TaskStatusPollResponseTests.java
@@ -0,0 +1,41 @@
+package ai.docling.serve.api.task.response;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * Unit tests for {@link TaskStatusPollResponse}.
+ */
+class TaskStatusPollResponseTests {
+
+ @Test
+ void createTaskStatusPollResponseWithFailure() {
+ TaskFailureInfo failure = TaskFailureInfo.builder()
+ .category(FailureCategory.SOURCE_UNAVAILABLE)
+ .message("Source document could not be reached.")
+ .retryable(true)
+ .phase(FailurePhase.SOURCE_ENUMERATION)
+ .build();
+
+ TaskStatusPollResponse response = TaskStatusPollResponse.builder()
+ .taskId("1")
+ .taskStatus(TaskStatus.FAILURE)
+ .errorMessage("Internal processing error.")
+ .failure(failure)
+ .build();
+
+ assertThat(response.getFailure()).isEqualTo(failure);
+ }
+
+ @Test
+ void createTaskStatusPollResponseWithoutFailure() {
+ TaskStatusPollResponse response = TaskStatusPollResponse.builder()
+ .taskId("1")
+ .taskStatus(TaskStatus.SUCCESS)
+ .build();
+
+ assertThat(response.getFailure()).isNull();
+ }
+
+}
diff --git a/docling-serve/docling-serve-client/src/main/java/ai/docling/serve/client/DoclingServeJackson2Client.java b/docling-serve/docling-serve-client/src/main/java/ai/docling/serve/client/DoclingServeJackson2Client.java
index db34bb4a..9baf400a 100644
--- a/docling-serve/docling-serve-client/src/main/java/ai/docling/serve/client/DoclingServeJackson2Client.java
+++ b/docling-serve/docling-serve-client/src/main/java/ai/docling/serve/client/DoclingServeJackson2Client.java
@@ -81,7 +81,10 @@ protected String writeValueAsString(T value) {
public static final class Builder extends DoclingServeClientBuilder {
private JsonMapper.Builder jsonMapperBuilder = JsonMapper.builder()
// This is the default in Jackson 3 whereas it needs to be set explicitly in Jackson 2.
- .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
+ // Lets enums with a @JsonEnumDefaultValue constant (e.g. FailureCategory.UNKNOWN) absorb
+ // values added upstream after this library's enum was last updated, instead of failing.
+ .configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE, true);
private Builder() {
}
diff --git a/docling-serve/docling-serve-client/src/main/java/ai/docling/serve/client/DoclingServeJackson3Client.java b/docling-serve/docling-serve-client/src/main/java/ai/docling/serve/client/DoclingServeJackson3Client.java
index 2fd33295..0b9d60db 100644
--- a/docling-serve/docling-serve-client/src/main/java/ai/docling/serve/client/DoclingServeJackson3Client.java
+++ b/docling-serve/docling-serve-client/src/main/java/ai/docling/serve/client/DoclingServeJackson3Client.java
@@ -3,6 +3,7 @@
import static ai.docling.serve.api.util.ValidationUtils.ensureNotNull;
import tools.jackson.core.JacksonException;
+import tools.jackson.databind.cfg.EnumFeature;
import tools.jackson.databind.json.JsonMapper;
/**
@@ -71,7 +72,10 @@ protected String writeValueAsString(T value) {
* or {@link DoclingServeJackson3Client#toBuilder()} to obtain a builder instance.
*/
public static final class Builder extends DoclingServeClientBuilder {
- private JsonMapper.Builder jsonMapperBuilder = JsonMapper.builder();
+ private JsonMapper.Builder jsonMapperBuilder = JsonMapper.builder()
+ // Lets enums with a @JsonEnumDefaultValue constant (e.g. FailureCategory.UNKNOWN) absorb
+ // values added upstream after this library's enum was last updated, instead of failing.
+ .enable(EnumFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE);
private Builder() {
}
diff --git a/docling-serve/docling-serve-client/src/test/java/ai/docling/serve/client/AbstractDoclingServeClientTests.java b/docling-serve/docling-serve-client/src/test/java/ai/docling/serve/client/AbstractDoclingServeClientTests.java
index 17b39ae8..3774cd66 100644
--- a/docling-serve/docling-serve-client/src/test/java/ai/docling/serve/client/AbstractDoclingServeClientTests.java
+++ b/docling-serve/docling-serve-client/src/test/java/ai/docling/serve/client/AbstractDoclingServeClientTests.java
@@ -746,7 +746,7 @@ class AsyncTaskFailureTests {
"num_failed": 1
}
""";
- private static final String TASK_META_STRING = "TaskStatusMetadata(numDocs=1, numProcessed=1, numSucceeded=0, numFailed=1)";
+ private static final String TASK_META_STRING = "TaskStatusMetadata(numDocs=1, numProcessed=1, numSucceeded=0, numPartiallySucceeded=null, numFailed=1)";
@AfterEach
void resetStubs() {
diff --git a/docling-serve/docling-serve-client/src/test/java/ai/docling/serve/client/FailureDeserializationTests.java b/docling-serve/docling-serve-client/src/test/java/ai/docling/serve/client/FailureDeserializationTests.java
new file mode 100644
index 00000000..a0b3f962
--- /dev/null
+++ b/docling-serve/docling-serve-client/src/test/java/ai/docling/serve/client/FailureDeserializationTests.java
@@ -0,0 +1,88 @@
+package ai.docling.serve.client;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.net.URI;
+import java.util.Map;
+
+import org.junit.jupiter.api.Test;
+
+import ai.docling.serve.api.task.response.FailureCategory;
+import ai.docling.serve.api.task.response.FailurePhase;
+import ai.docling.serve.api.task.response.TaskFailureInfo;
+import ai.docling.serve.api.task.response.TaskStatusPollResponse;
+
+/**
+ * Verifies that {@link TaskStatusPollResponse#getFailure()}, {@link FailureCategory} and
+ * {@link FailurePhase} deserialize correctly.
+ *
+ * Every case runs through a default-built {@link DoclingServeJackson2Client} and
+ * {@link DoclingServeJackson3Client} rather than a mapper configured by the test, so that
+ * dropping the unknown-enum fallback from either client's default mapper fails these tests.
+ */
+class FailureDeserializationTests {
+ private static final String TASK_STATUS_WITH_FAILURE_JSON = """
+ {
+ "task_id": "1",
+ "task_status": "failure",
+ "error_message": "Internal processing error.",
+ "failure": {
+ "category": "%s",
+ "message": "Source document could not be reached.",
+ "retryable": true,
+ "phase": "%s",
+ "details": {"source_kind": "http"}
+ }
+ }
+ """;
+
+ private final DoclingServeJackson2Client jackson2Client = DoclingServeJackson2Client.builder()
+ .baseUrl(URI.create("http://localhost"))
+ .build();
+
+ private final DoclingServeJackson3Client jackson3Client = DoclingServeJackson3Client.builder()
+ .baseUrl(URI.create("http://localhost"))
+ .build();
+
+ @Test
+ void jackson2DeserializesKnownFailureValues() {
+ var failure = readFailure(this.jackson2Client, "source_unavailable", "source_enumeration");
+
+ assertFailure(failure, FailureCategory.SOURCE_UNAVAILABLE, FailurePhase.SOURCE_ENUMERATION);
+ }
+
+ @Test
+ void jackson2DeserializesUnrecognizedFailureValuesAsUnknown() {
+ var failure = readFailure(this.jackson2Client, "a_future_category", "a_future_phase");
+
+ assertFailure(failure, FailureCategory.UNKNOWN, FailurePhase.UNKNOWN);
+ }
+
+ @Test
+ void jackson3DeserializesKnownFailureValues() {
+ var failure = readFailure(this.jackson3Client, "source_unavailable", "source_enumeration");
+
+ assertFailure(failure, FailureCategory.SOURCE_UNAVAILABLE, FailurePhase.SOURCE_ENUMERATION);
+ }
+
+ @Test
+ void jackson3DeserializesUnrecognizedFailureValuesAsUnknown() {
+ var failure = readFailure(this.jackson3Client, "a_future_category", "a_future_phase");
+
+ assertFailure(failure, FailureCategory.UNKNOWN, FailurePhase.UNKNOWN);
+ }
+
+ private static TaskFailureInfo readFailure(DoclingServeClient client, String category, String phase) {
+ var json = TASK_STATUS_WITH_FAILURE_JSON.formatted(category, phase);
+ return client.readValue(json, TaskStatusPollResponse.class).getFailure();
+ }
+
+ private static void assertFailure(TaskFailureInfo failure, FailureCategory category, FailurePhase phase) {
+ assertThat(failure).isNotNull();
+ assertThat(failure.getCategory()).isEqualTo(category);
+ assertThat(failure.getPhase()).isEqualTo(phase);
+ assertThat(failure.getMessage()).isEqualTo("Source document could not be reached.");
+ assertThat(failure.isRetryable()).isTrue();
+ assertThat(failure.getDetails()).isEqualTo(Map.of("source_kind", "http"));
+ }
+}
diff --git a/docs/src/doc/docs/whats-new.md b/docs/src/doc/docs/whats-new.md
index b9cb08ad..8cae86f6 100644
--- a/docs/src/doc/docs/whats-new.md
+++ b/docs/src/doc/docs/whats-new.md
@@ -7,6 +7,9 @@ Docling Java {{ gradle.project_version }} includes important breaking changes, a
### {{ gradle.project_version }}
* **`DoclingDocument` keeps required empty strings when it is serialized** — Serializing a `DoclingDocument` used to drop the `text` and `orig` fields when they were empty strings, such as `"text": ""` on a formula converted without formula enrichment, or on a list item that only introduces a nested list. These fields are required by the [`DoclingDocument` JSON schema](https://github.com/docling-project/docling-core/tree/main/docs/schemas), so a document written back to JSON failed validation and could not be chunked. The required `text` and `orig` fields are now always written, even when empty. Empty lists are still left out.
+* **Map the structured `failure` field of the task status response** — `TaskStatusPollResponse` now exposes `failure`, a new `TaskFailureInfo` with `category` (`FailureCategory`), `message`, `retryable`, `phase` (`FailurePhase`), and `details`. This is populated only by Docling Serve deployments using the Ray orchestrator (v1.25.0+); other orchestrators continue to report only `errorMessage`. `FailureCategory` and `FailurePhase` are extensible upstream, so an unrecognized value deserializes to `UNKNOWN` instead of failing, when using the default JSON mappers in `docling-serve-client`; a consumer supplying its own Jackson 2 or Jackson 3 mapper must enable the equivalent "read unknown enum as default" feature to get the same behavior.
+* **`ErrorItem` gains `category` and `pageNo`** — `ErrorItem` now maps the upstream `category` (`FailureCategory`) and `page_no` fields, matching `ErrorItem.category`/`page_no` added upstream.
+* **`TaskStatusMetadata` gains `numPartiallySucceeded`** — `TaskStatusMetadata` now maps the upstream `num_partially_succeeded` field.
### 0.5.2