Skip to content

Commit 5448f3c

Browse files
committed
feat(ai-guard): return SDS findings into SDK Response
1 parent 93c3816 commit 5448f3c

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

dd-java-agent/agent-aiguard/src/main/java/com/datadog/aiguard/AIGuardInternal.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,9 @@ public Evaluation evaluate(final List<Message> messages, final Options options)
270270
WafMetricCollector.get().aiGuardRequest(action, shouldBlock);
271271
if (shouldBlock) {
272272
span.setTag(BLOCKED_TAG, true);
273-
throw new AIGuardAbortError(action, reason, tags);
273+
throw new AIGuardAbortError(action, reason, tags, sdsFindings);
274274
}
275-
return new Evaluation(action, reason, tags);
275+
return new Evaluation(action, reason, tags, sdsFindings);
276276
}
277277
} catch (AIGuardAbortError e) {
278278
span.addThrowable(e);

dd-trace-api/src/main/java/datadog/trace/api/aiguard/AIGuard.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,15 @@ public static class AIGuardAbortError extends RuntimeException {
6969
private final Action action;
7070
private final String reason;
7171
private final List<String> tags;
72+
private final List<?> sds;
7273

73-
public AIGuardAbortError(final Action action, final String reason, final List<String> tags) {
74+
public AIGuardAbortError(
75+
final Action action, final String reason, final List<String> tags, final List<?> sds) {
7476
super(reason);
7577
this.action = action;
7678
this.reason = reason;
7779
this.tags = tags;
80+
this.sds = sds != null ? sds : Collections.emptyList();
7881
}
7982

8083
public Action getAction() {
@@ -88,6 +91,10 @@ public String getReason() {
8891
public List<String> getTags() {
8992
return tags;
9093
}
94+
95+
public List<?> getSds() {
96+
return sds;
97+
}
9198
}
9299

93100
/**
@@ -149,18 +156,22 @@ public static class Evaluation {
149156
final Action action;
150157
final String reason;
151158
final List<String> tags;
159+
final List<?> sds;
152160

153161
/**
154162
* Creates a new evaluation result.
155163
*
156164
* @param action the recommended action for the evaluated content
157165
* @param reason human-readable explanation for the decision
158166
* @param tags list of tags associated with the evaluation (e.g. indirect-prompt-injection)
167+
* @param sds list of Sensitive Data Scanner findings
159168
*/
160-
public Evaluation(final Action action, final String reason, final List<String> tags) {
169+
public Evaluation(
170+
final Action action, final String reason, final List<String> tags, final List<?> sds) {
161171
this.action = action;
162172
this.reason = reason;
163173
this.tags = tags;
174+
this.sds = sds != null ? sds : Collections.emptyList();
164175
}
165176

166177
/**
@@ -189,6 +200,15 @@ public String getReason() {
189200
public List<String> getTags() {
190201
return tags;
191202
}
203+
204+
/**
205+
* Returns the list of Sensitive Data Scanner findings.
206+
*
207+
* @return list of SDS findings.
208+
*/
209+
public List<?> getSds() {
210+
return sds;
211+
}
192212
}
193213

194214
/**

dd-trace-api/src/main/java/datadog/trace/api/aiguard/noop/NoOpEvaluator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ public final class NoOpEvaluator implements Evaluator {
1313

1414
@Override
1515
public Evaluation evaluate(final List<Message> messages, final Options options) {
16-
return new Evaluation(ALLOW, "AI Guard is not enabled", emptyList());
16+
return new Evaluation(ALLOW, "AI Guard is not enabled", emptyList(), emptyList());
1717
}
1818
}

0 commit comments

Comments
 (0)