Skip to content

Commit df53803

Browse files
finito
1 parent aab484c commit df53803

File tree

6 files changed

+59
-10
lines changed

6 files changed

+59
-10
lines changed

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

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class DpiMasking implements MaskingProvider {
3333
@Nonnull DPIConfig.MethodEnum maskingMethod;
3434
@Nonnull List<DPIEntities> entities;
3535
boolean maskGroundingInput;
36+
@Nonnull List<String> allowList;
3637

3738
/**
3839
* Build a configuration applying anonymization.
@@ -67,7 +68,7 @@ public static class Builder {
6768
*
6869
* @param entity An entity type to mask (required)
6970
* @param entities Additional entity types to mask (optional)
70-
* @return A configured {@link DpiMasking} instance
71+
* @return A new {@link DpiMasking} instance
7172
* @see DPIEntities
7273
*/
7374
@Nonnull
@@ -76,12 +77,29 @@ public DpiMasking withEntities(
7677
val entitiesList = new ArrayList<DPIEntities>();
7778
entitiesList.add(entity);
7879
entitiesList.addAll(Arrays.asList(entities));
79-
return new DpiMasking(maskingMethod, entitiesList, false);
80+
return new DpiMasking(maskingMethod, entitiesList, false, List.of());
8081
}
8182
}
8283

83-
public DpiMasking withGroundingEnabled() {
84-
return new DpiMasking(maskingMethod, entities, true);
84+
/**
85+
* If grounding is used, the input text will be masked.
86+
*
87+
* @return A new {@link DpiMasking} instance
88+
*/
89+
@Nonnull
90+
public DpiMasking withMaskGroundingEnabled() {
91+
return new DpiMasking(maskingMethod, entities, true, List.of());
92+
}
93+
94+
/**
95+
* Set words that should not be masked.
96+
*
97+
* @param allowList List of strings that should not be masked
98+
* @return A new {@link DpiMasking} instance
99+
*/
100+
@Nonnull
101+
public DpiMasking withAllowList(@Nonnull final List<String> allowList) {
102+
return new DpiMasking(maskingMethod, entities, maskGroundingInput, allowList);
85103
}
86104

87105
@Nonnull
@@ -92,6 +110,7 @@ public MaskingProviderConfig createConfig() {
92110
.type(SAP_DATA_PRIVACY_INTEGRATION)
93111
.method(maskingMethod)
94112
.entities(entitiesDTO)
95-
.maskGroundingInput(DPIConfigMaskGroundingInput.create().enabled(maskGroundingInput));
113+
.maskGroundingInput(DPIConfigMaskGroundingInput.create().enabled(maskGroundingInput))
114+
.allowlist(allowList);
96115
}
97116
}

orchestration/src/test/java/com/sap/ai/sdk/orchestration/OrchestrationUnitTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,13 @@ void testGrounding() throws IOException {
170170
GroundingModuleConfig.create()
171171
.type(GroundingModuleConfig.TypeEnum.DOCUMENT_GROUNDING_SERVICE)
172172
.config(groundingConfigConfig);
173-
final var configWithGrounding = config.withGroundingConfig(groundingConfig);
173+
val maskingConfig = // optional masking configuration
174+
DpiMasking.anonymization()
175+
.withEntities(DPIEntities.SENSITIVE_DATA)
176+
.withMaskGroundingEnabled()
177+
.withAllowList(List.of("SAP", "Joule"));
178+
final var configWithGrounding =
179+
config.withGroundingConfig(groundingConfig).withMaskingConfig(maskingConfig);
174180

175181
final Map<String, String> inputParams =
176182
Map.of("query", "String used for similarity search in database");

orchestration/src/test/resources/groundingRequest.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@
2121
"defaults" : { },
2222
"tools" : [ ]
2323
},
24+
"masking_module_config" : {
25+
"masking_providers" : [ {
26+
"type" : "sap_data_privacy_integration",
27+
"method" : "anonymization",
28+
"entities" : [ {
29+
"type" : "profile-sensitive-data"
30+
} ],
31+
"allowlist" : [ "SAP", "Joule" ],
32+
"mask_grounding_input" : {
33+
"enabled" : true
34+
}
35+
} ]
36+
},
2437
"grounding_module_config" : {
2538
"type" : "document_grounding_service",
2639
"config" : {
@@ -53,4 +66,4 @@
5366
"query" : "String used for similarity search in database"
5467
},
5568
"messages_history" : [ ]
56-
}
69+
}

orchestration/src/test/resources/maskingRequest.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@
3333
"type": "profile-phone"
3434
}
3535
],
36-
"allowlist" : [ ]
36+
"allowlist" : [ ],
37+
"mask_grounding_input" : {
38+
"enabled" : false
39+
}
3740
}
3841
]
3942
}

sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/services/OrchestrationService.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,13 @@ public OrchestrationChatResponse grounding(@Nonnull final String userMessage) {
335335

336336
val groundingConfig = Grounding.create().filters(databaseFilter);
337337
val prompt = groundingConfig.createGroundingPrompt(userMessage);
338-
val maskingConfig = DpiMasking.anonymization().withEntities(DPIEntities.PERSON).withGroundingEnabled();
339-
val configWithGrounding = config.withGrounding(groundingConfig).withMaskingConfig(maskingConfig);
338+
val maskingConfig = // optional masking configuration
339+
DpiMasking.anonymization()
340+
.withEntities(DPIEntities.SENSITIVE_DATA)
341+
.withMaskGroundingEnabled()
342+
.withAllowList(List.of("SAP", "Joule"));
343+
val configWithGrounding =
344+
config.withGrounding(groundingConfig).withMaskingConfig(maskingConfig);
340345

341346
return client.chatCompletion(prompt, configWithGrounding);
342347
}

sample-code/spring-app/src/test/java/com/sap/ai/sdk/app/controllers/OrchestrationTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ void testGrounding() {
176176
assertThat(result.getModuleResults().getGrounding()).isNotNull();
177177
assertThat(result.getModuleResults().getGrounding().getData()).isNotNull();
178178
assertThat(result.getModuleResults().getGrounding().getMessage()).isEqualTo("grounding result");
179+
180+
var maskingResult = result.getModuleResults().getInputMasking();
181+
assertThat(maskingResult.getMessage()).isNotEmpty();
179182
}
180183

181184
@Test

0 commit comments

Comments
 (0)