From f5c6af742245a580e20306ad59a219bccdf01a38 Mon Sep 17 00:00:00 2001 From: box-sdk-build Date: Tue, 27 Jan 2026 11:20:15 -0800 Subject: [PATCH 1/2] feat: add confidence scores for structured extract (box/box-openapi#582) --- .codegen.json | 2 +- .../AiExtractStructured.java | 23 +++++++++++++++- .../AiExtractStructuredResponse.java | 26 ++++++++++++++++++- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/.codegen.json b/.codegen.json index 8c2a6522c..41241aeb2 100644 --- a/.codegen.json +++ b/.codegen.json @@ -1 +1 @@ -{ "engineHash": "f9e2519", "specHash": "f8fb08c", "version": "10.4.0" } +{ "engineHash": "f9e2519", "specHash": "ccdb456", "version": "10.4.0" } diff --git a/src/main/java/com/box/sdkgen/schemas/aiextractstructured/AiExtractStructured.java b/src/main/java/com/box/sdkgen/schemas/aiextractstructured/AiExtractStructured.java index 4e23ae994..582201abe 100644 --- a/src/main/java/com/box/sdkgen/schemas/aiextractstructured/AiExtractStructured.java +++ b/src/main/java/com/box/sdkgen/schemas/aiextractstructured/AiExtractStructured.java @@ -31,6 +31,10 @@ public class AiExtractStructured extends SerializableObject { */ protected List fields; + /** A flag to indicate whether confidence scores for every extracted field should be returned. */ + @JsonProperty("include_confidence_score") + protected Boolean includeConfidenceScore; + @JsonProperty("ai_agent") protected AiExtractStructuredAgent aiAgent; @@ -44,6 +48,7 @@ protected AiExtractStructured(Builder builder) { this.items = builder.items; this.metadataTemplate = builder.metadataTemplate; this.fields = builder.fields; + this.includeConfidenceScore = builder.includeConfidenceScore; this.aiAgent = builder.aiAgent; markNullableFieldsAsSet(builder.getExplicitlySetNullableFields()); } @@ -60,6 +65,10 @@ public List getFields() { return fields; } + public Boolean getIncludeConfidenceScore() { + return includeConfidenceScore; + } + public AiExtractStructuredAgent getAiAgent() { return aiAgent; } @@ -76,12 +85,13 @@ public boolean equals(Object o) { return Objects.equals(items, casted.items) && Objects.equals(metadataTemplate, casted.metadataTemplate) && Objects.equals(fields, casted.fields) + && Objects.equals(includeConfidenceScore, casted.includeConfidenceScore) && Objects.equals(aiAgent, casted.aiAgent); } @Override public int hashCode() { - return Objects.hash(items, metadataTemplate, fields, aiAgent); + return Objects.hash(items, metadataTemplate, fields, includeConfidenceScore, aiAgent); } @Override @@ -99,6 +109,10 @@ public String toString() { + fields + '\'' + ", " + + "includeConfidenceScore='" + + includeConfidenceScore + + '\'' + + ", " + "aiAgent='" + aiAgent + '\'' @@ -113,6 +127,8 @@ public static class Builder extends NullableFieldTracker { protected List fields; + protected Boolean includeConfidenceScore; + protected AiExtractStructuredAgent aiAgent; public Builder(List items) { @@ -130,6 +146,11 @@ public Builder fields(List fields) { return this; } + public Builder includeConfidenceScore(Boolean includeConfidenceScore) { + this.includeConfidenceScore = includeConfidenceScore; + return this; + } + public Builder aiAgent(AiAgentReference aiAgent) { this.aiAgent = new AiExtractStructuredAgent(aiAgent); return this; diff --git a/src/main/java/com/box/sdkgen/schemas/aiextractstructuredresponse/AiExtractStructuredResponse.java b/src/main/java/com/box/sdkgen/schemas/aiextractstructuredresponse/AiExtractStructuredResponse.java index 42e94c96e..3cdc770f9 100644 --- a/src/main/java/com/box/sdkgen/schemas/aiextractstructuredresponse/AiExtractStructuredResponse.java +++ b/src/main/java/com/box/sdkgen/schemas/aiextractstructuredresponse/AiExtractStructuredResponse.java @@ -28,6 +28,13 @@ public class AiExtractStructuredResponse extends SerializableObject { @JsonProperty("completion_reason") protected String completionReason; + /** + * The confidence score numeric values for each extracted field as a JSON dictionary. This can be + * empty if no field could be extracted. + */ + @JsonProperty("confidence_score") + protected Map confidenceScore; + @JsonProperty("ai_agent_info") protected AiAgentInfo aiAgentInfo; @@ -44,6 +51,7 @@ protected AiExtractStructuredResponse(Builder builder) { this.answer = builder.answer; this.createdAt = builder.createdAt; this.completionReason = builder.completionReason; + this.confidenceScore = builder.confidenceScore; this.aiAgentInfo = builder.aiAgentInfo; markNullableFieldsAsSet(builder.getExplicitlySetNullableFields()); } @@ -60,6 +68,10 @@ public String getCompletionReason() { return completionReason; } + public Map getConfidenceScore() { + return confidenceScore; + } + public AiAgentInfo getAiAgentInfo() { return aiAgentInfo; } @@ -76,12 +88,13 @@ public boolean equals(Object o) { return Objects.equals(answer, casted.answer) && Objects.equals(createdAt, casted.createdAt) && Objects.equals(completionReason, casted.completionReason) + && Objects.equals(confidenceScore, casted.confidenceScore) && Objects.equals(aiAgentInfo, casted.aiAgentInfo); } @Override public int hashCode() { - return Objects.hash(answer, createdAt, completionReason, aiAgentInfo); + return Objects.hash(answer, createdAt, completionReason, confidenceScore, aiAgentInfo); } @Override @@ -99,6 +112,10 @@ public String toString() { + completionReason + '\'' + ", " + + "confidenceScore='" + + confidenceScore + + '\'' + + ", " + "aiAgentInfo='" + aiAgentInfo + '\'' @@ -113,6 +130,8 @@ public static class Builder extends NullableFieldTracker { protected String completionReason; + protected Map confidenceScore; + protected AiAgentInfo aiAgentInfo; public Builder(Map answer, OffsetDateTime createdAt) { @@ -126,6 +145,11 @@ public Builder completionReason(String completionReason) { return this; } + public Builder confidenceScore(Map confidenceScore) { + this.confidenceScore = confidenceScore; + return this; + } + public Builder aiAgentInfo(AiAgentInfo aiAgentInfo) { this.aiAgentInfo = aiAgentInfo; return this; From 61ff7626a52ff32d24cf1afe3ea873b6e9e9e599 Mon Sep 17 00:00:00 2001 From: box-sdk-build Date: Wed, 28 Jan 2026 08:20:11 -0800 Subject: [PATCH 2/2] test: test AI confidence score (box/box-codegen#919) --- .codegen.json | 2 +- docs/ai.md | 2 +- src/test/java/com/box/sdkgen/ai/AiITest.java | 12 ++++++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.codegen.json b/.codegen.json index 41241aeb2..49ca5c829 100644 --- a/.codegen.json +++ b/.codegen.json @@ -1 +1 @@ -{ "engineHash": "f9e2519", "specHash": "ccdb456", "version": "10.4.0" } +{ "engineHash": "b181eba", "specHash": "ccdb456", "version": "10.4.0" } diff --git a/docs/ai.md b/docs/ai.md index cb2746275..157ed87c8 100644 --- a/docs/ai.md +++ b/docs/ai.md @@ -149,7 +149,7 @@ See the endpoint docs at ``` -client.getAi().createAiExtractStructured(new AiExtractStructured.Builder(Arrays.asList(new AiItemBase(file.getId()))).fields(Arrays.asList(new AiExtractStructuredFieldsField.Builder("firstName").description("Person first name").displayName("First name").prompt("What is the your first name?").type("string").build(), new AiExtractStructuredFieldsField.Builder("lastName").description("Person last name").displayName("Last name").prompt("What is the your last name?").type("string").build(), new AiExtractStructuredFieldsField.Builder("dateOfBirth").description("Person date of birth").displayName("Birth date").prompt("What is the date of your birth?").type("date").build(), new AiExtractStructuredFieldsField.Builder("age").description("Person age").displayName("Age").prompt("How old are you?").type("float").build(), new AiExtractStructuredFieldsField.Builder("hobby").description("Person hobby").displayName("Hobby").prompt("What is your hobby?").type("multiSelect").options(Arrays.asList(new AiExtractStructuredFieldsOptionsField("guitar"), new AiExtractStructuredFieldsOptionsField("books"))).build())).aiAgent(aiExtractStructuredAgentBasicTextConfig).build()) +client.getAi().createAiExtractStructured(new AiExtractStructured.Builder(Arrays.asList(new AiItemBase(file.getId()))).fields(Arrays.asList(new AiExtractStructuredFieldsField.Builder("firstName").description("Person first name").displayName("First name").prompt("What is the your first name?").type("string").build(), new AiExtractStructuredFieldsField.Builder("lastName").description("Person last name").displayName("Last name").prompt("What is the your last name?").type("string").build(), new AiExtractStructuredFieldsField.Builder("dateOfBirth").description("Person date of birth").displayName("Birth date").prompt("What is the date of your birth?").type("date").build(), new AiExtractStructuredFieldsField.Builder("age").description("Person age").displayName("Age").prompt("How old are you?").type("float").build(), new AiExtractStructuredFieldsField.Builder("hobby").description("Person hobby").displayName("Hobby").prompt("What is your hobby?").type("multiSelect").options(Arrays.asList(new AiExtractStructuredFieldsOptionsField("guitar"), new AiExtractStructuredFieldsOptionsField("books"))).build())).includeConfidenceScore(true).aiAgent(aiExtractStructuredAgentBasicTextConfig).build()) ``` ### Arguments diff --git a/src/test/java/com/box/sdkgen/ai/AiITest.java b/src/test/java/com/box/sdkgen/ai/AiITest.java index dbfbe8533..892e21d9e 100644 --- a/src/test/java/com/box/sdkgen/ai/AiITest.java +++ b/src/test/java/com/box/sdkgen/ai/AiITest.java @@ -261,7 +261,10 @@ public void testAiExtractStructuredWithFields() { String.join("", getUuid(), ".txt"), new UploadFileRequestBodyAttributesParentField("0")), stringToByteStream( - "My name is John Doe. I was born in 4th July 1990. I am 34 years old. My hobby is guitar."))); + String.join( + "", + "My name is John Doe. I was born in 4th July 1990. I am 34 years old. My hobby is guitar. My UUID is ", + getUuid())))); FileFull file = uploadedFiles.getEntries().get(0); delayInSeconds(5); AiExtractStructuredResponse response = @@ -305,8 +308,10 @@ public void testAiExtractStructuredWithFields() { new AiExtractStructuredFieldsOptionsField("guitar"), new AiExtractStructuredFieldsOptionsField("books"))) .build())) + .includeConfidenceScore(true) .aiAgent(aiExtractStructuredAgentBasicTextConfig) .build()); + assert !(response.getConfidenceScore() == null); assert convertToString(response.getAnswer().get("hobby")) .equals(convertToString(Arrays.asList("guitar"))); assert convertToString(response.getAnswer().get("firstName")).equals("John"); @@ -328,7 +333,10 @@ public void testAiExtractStructuredWithMetadataTemplate() { String.join("", getUuid(), ".txt"), new UploadFileRequestBodyAttributesParentField("0")), stringToByteStream( - "My name is John Doe. I was born in 4th July 1990. I am 34 years old. My hobby is guitar."))); + String.join( + "", + "My name is John Doe. I was born in 4th July 1990. I am 34 years old. My hobby is guitar. My UUID is ", + getUuid())))); FileFull file = uploadedFiles.getEntries().get(0); delayInSeconds(5); String templateKey = String.join("", "key", getUuid());