Skip to content

feat(ai-guard): apply sensitive data redaction from evaluate responses - #12394

Open
manuel-alvarez-alvarez wants to merge 2 commits into
masterfrom
malvarez/ai-guard-sds-redaction
Open

feat(ai-guard): apply sensitive data redaction from evaluate responses#12394
manuel-alvarez-alvarez wants to merge 2 commits into
masterfrom
malvarez/ai-guard-sds-redaction

Conversation

@manuel-alvarez-alvarez

@manuel-alvarez-alvarez manuel-alvarez-alvarez commented Sep 3, 2026

Copy link
Copy Markdown
Member

What Does This Do

/evaluate responses may now carry a top-level redaction_replacements array of {path, replacement} entries. Its presence is the signal to redact — there is no separate flag. The service returns the fully redacted string per path, so the tracer resolves the path and overwrites that one string verbatim: no offsets, no encodings, no merging.

  • Evaluation.getMessages() returns the evaluated messages, redacted when redaction was applied; getRedactionReplacements() reports what was applied. Callers should forward getMessages() to their LLM provider.
  • Meta-struct reports the redacted conversation, including on the blocked path. AIGuardAbortError deliberately carries no messages.
  • DD_AI_GUARD_REDACTION_ENABLED (default true) is a kill switch, checked before any redaction work.
  • New ai_guard.redacted span tag and a redacted tag on the ai_guard.requests telemetry metric. Both are omitted entirely when the kill switch is off, so an absent tag means "redaction is off" and stays distinguishable from false.

Redaction is applied copy-on-write — the caller's list is never mutated, only redacted messages are rebuilt, and the same list reference is returned when nothing changed. Unresolvable paths, non-string targets, and missing or conflicting replacements are skipped fail-safe and counted, never raised.

Motivation

Until now, AI Guard's backend applies a Sensitive Data Scanner (SDS) and returns matches in the sds_findings field of its API response. Those matches are purely informative today: they are surfaced through the SDK and presented in the UI, but nothing is transformed.

This PR extends that capability to sensitive data redaction. Sensitive data is removed from LLM interactions (before a prompt reaches the provider, and on the provider's responses), and the same redaction is applied to the data sent to the backend for use in the UI.

Additional Notes

Implements the tracer side of the AI Guard Sensitive Data Redaction RFC.

Contributor Checklist

APPSEC-69390

@manuel-alvarez-alvarez manuel-alvarez-alvarez added type: feature Enhancements and improvements tag: ai generated Largely based on code generated by an AI or LLM comp: ai-guard AI Guard labels Sep 3, 2026
@manuel-alvarez-alvarez
manuel-alvarez-alvarez force-pushed the malvarez/ai-guard-sds-redaction branch from 120a7e9 to 49d1167 Compare September 3, 2026 11:07
@manuel-alvarez-alvarez
manuel-alvarez-alvarez marked this pull request as ready for review September 3, 2026 11:10
@manuel-alvarez-alvarez
manuel-alvarez-alvarez requested review from claponcet, dougqh and jandro996 and removed request for a team September 3, 2026 11:10

@datadog-datadog-prod-us1-2 datadog-datadog-prod-us1-2 Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Datadog Autotest: FAIL

An enabled redaction request that fails before response processing has no redaction tag on its span or error metric. The missing tag makes the request look like the kill switch is off.

Open Bits AI session

🤖 Datadog Autotest · Commit 49d1167 · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 49d1167c8e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@datadog-datadog-prod-us1-2

This comment has been minimized.

return AIGuardRedaction.DISABLED;
}
span.setTag(REDACTED_TAG, redaction.redacted());
if (redaction.skipped > 0) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should also report redaction_error telemetry on failure

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is it defined in the RFC? (I couldn't find it 😓)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was mentioned on the tracer recommended behavior

If two entries for the same path carry different replacement values (a backend bug), the tracer skips that path and records a telemetry error rather than guessing

But not listed on telemetry part.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we update the RFC or add and addendum?, just to set redaction_error as the tag for this particular case

@dd-octo-sts

dd-octo-sts Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 14.07 s 13.98 s [-0.3%; +1.5%] (no difference)
startup:insecure-bank:tracing:Agent 12.93 s 12.99 s [-1.2%; +0.3%] (no difference)
startup:petclinic:appsec:Agent 17.05 s 17.47 s [-6.7%; +1.9%] (no difference)
startup:petclinic:iast:Agent 17.45 s 17.54 s [-1.3%; +0.3%] (no difference)
startup:petclinic:profiling:Agent 17.31 s 17.41 s [-1.6%; +0.4%] (no difference)
startup:petclinic:sca:Agent 17.12 s 16.65 s [-3.5%; +9.1%] (unstable)
startup:petclinic:tracing:Agent 16.68 s 16.67 s [-1.0%; +1.1%] (no difference)

Commit: d8d7fb79 · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: ai-guard AI Guard tag: ai generated Largely based on code generated by an AI or LLM type: feature Enhancements and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants