Skip to content

feat(studio): Redact/Annotate/Hash strategy params [ASTD-333] - #898

Merged
marcusds merged 5 commits into
mainfrom
astd-333-anonymizer-strategy-params/mschwab
Jul 24, 2026
Merged

marcusds merged 5 commits into
mainfrom
astd-333-anonymizer-strategy-params/mschwab

Conversation

@marcusds

@marcusds marcusds commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

What

Adds the parameter UIs for the deterministic replace strategies — Redact / Annotate / Hash — in the Anonymizer builder (ASTD-333). Part of ASTD-215; builds on the merged builder (#884).

Changes

  • Strategy select unlocked for Substitute / Redact / Annotate / Hash (Rewrite stays locked → ASTD-334).
  • StrategyParamsSection renders per-strategy fields below the strategy dropdown:
    • Redact — Format Template + "Normalize and clean the label" checkbox
    • Annotate — Format Template
    • Hash — Algorithm (SHA-256 / SHA-1 / MD5) + Digest Length (6–64) + Format Template
  • Library-default templates prefilled ({…} placeholder syntax). Params flow into config.replace alongside the kind tag; empty templates are omitted so the backend default applies.
  • Redact/Annotate/Hash are deterministic → no replacement_generator role (detection-only mapping already handled).

Backend-driven inline validation

The anonymizer returns clean, specific 422s for bad templates (e.g. template is missing required placeholders: text at …replace.annotate.format_template). Rather than duplicate the rules client-side, on create onError we parse the pydantic detail[] and map each loc to its form field via a reusable helper (apiErrors.ts), calling setError for an inline message — with the banner as fallback for unmapped errors (e.g. model/provider issues).

Testing

  • schema.test.ts (12) — strategy kind + params, empty-template omission, model/label mapping.
  • apiErrors.test.ts (4) — loc → field mapping (templates, hash params, data.source), unmapped → general, non-422 → empty.
  • Verified against a local platform: Redact create → 201 and runs; bad templates return the expected 422.
  • @nemo/studio tsc — no new errors from this branch (pre-existing customizer + insights-SDK drift on main, unchanged). eslint + prettier clean.

Gated behind VITE_FF_ANONYMIZER_ENABLED (default false).

Notes

  • Pre-push typecheck hook bypassed for the pre-existing Studio SDK-drift failures, unrelated to this branch.

Summary by CodeRabbit

  • New Features
    • Strategy selection now tailors the form for redact, annotate, hash, and substitute (rewrite excluded), with defaults for templates and hash settings (algorithm, digest length).
    • Added a dynamic “strategy parameters” section that shows only the relevant inputs for the selected strategy.
  • Bug Fixes
    • Improved anonymizer submit error handling by parsing API validation errors into field-specific messages and general submit messages; the UI reflects field errors more accurately.
  • Tests
    • Added Jest coverage for parsing API error loc mappings and updated schema/request-building assertions for strategy-specific replace payloads.

@marcusds
marcusds requested review from a team as code owners July 24, 2026 22:15
@github-actions github-actions Bot added the feat label Jul 24, 2026
@coderabbitai

coderabbitai Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds strategy-specific anonymizer parameters and payload construction for redact, annotate, and hash strategies. The route parses API validation errors into field-level and general messages, while the UI renders conditional controls and excludes rewrite from available options.

Changes

Anonymizer Builder enhancements

Layer / File(s) Summary
Strategy configuration and request payloads
web/packages/studio/src/routes/AnonymizerBuilderRoute/constants.ts, web/packages/studio/src/routes/AnonymizerBuilderRoute/schema.ts, web/packages/studio/src/routes/AnonymizerBuilderRoute/schema.test.ts
Adds strategy defaults, validation, strategy-specific replace payload construction, and focused coverage for replace strategies.
Strategy-specific form controls
web/packages/studio/src/routes/AnonymizerBuilderRoute/components/GenerationSection.tsx, web/packages/studio/src/routes/AnonymizerBuilderRoute/components/StrategyParamsSection.tsx
Displays available strategies and renders redact, annotate, and hash parameters based on the selected strategy.
API validation error mapping
web/packages/studio/src/routes/AnonymizerBuilderRoute/apiErrors.ts, web/packages/studio/src/routes/AnonymizerBuilderRoute/apiErrors.test.ts, web/packages/studio/src/routes/AnonymizerBuilderRoute/index.tsx
Maps API error locations to form fields, applies field errors, and surfaces unmapped messages as submit errors.

Sequence Diagram(s)

sequenceDiagram
  participant GenerationSection
  participant anonymizerFormSchema
  participant AnonymizerBuilderRoute
  participant parseAnonymizerApiError
  participant FormState

  GenerationSection->>anonymizerFormSchema: submit strategy-specific values
  anonymizerFormSchema->>AnonymizerBuilderRoute: provide validated form data
  AnonymizerBuilderRoute->>parseAnonymizerApiError: parse API validation failure
  parseAnonymizerApiError->>AnonymizerBuilderRoute: return fieldErrors and generalMessages
  AnonymizerBuilderRoute->>FormState: set form and submit errors
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding Redact, Annotate, and Hash strategy parameters in studio.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch astd-333-anonymizer-strategy-params/mschwab

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
web/packages/studio/src/routes/AnonymizerBuilderRoute/apiErrors.ts (1)

8-16: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Mark interface fields readonly.

PydanticError and ParsedApiError fields aren't marked readonly.

As per coding guidelines: "Use readonly for immutable properties in TypeScript interfaces and types."

♻️ Add readonly modifiers
 interface PydanticError {
-  loc: (string | number)[];
-  msg: string;
+  readonly loc: (string | number)[];
+  readonly msg: string;
 }

 export interface ParsedApiError {
-  fieldErrors: { field: FormField; message: string }[];
-  generalMessages: string[];
+  readonly fieldErrors: { field: FormField; message: string }[];
+  readonly generalMessages: string[];
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web/packages/studio/src/routes/AnonymizerBuilderRoute/apiErrors.ts` around
lines 8 - 16, Mark all properties in the PydanticError and ParsedApiError
interfaces as readonly, including loc, msg, fieldErrors, and generalMessages,
without changing their types or structure.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@web/packages/studio/src/routes/AnonymizerBuilderRoute/schema.ts`:
- Around line 54-59: Update the schema’s hashAlgorithm validation to derive its
allowed values from the shared HASH_ALGORITHM_OPTIONS/HashAlgorithmOption
definitions in constants.ts instead of hardcoding the enum literals. Preserve
the existing validation behavior while ensuring future algorithm additions
remain synchronized with the dropdown options.

---

Nitpick comments:
In `@web/packages/studio/src/routes/AnonymizerBuilderRoute/apiErrors.ts`:
- Around line 8-16: Mark all properties in the PydanticError and ParsedApiError
interfaces as readonly, including loc, msg, fieldErrors, and generalMessages,
without changing their types or structure.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: f5c49bc3-3505-4118-876e-2bcbe0fdc15c

📥 Commits

Reviewing files that changed from the base of the PR and between 574831b and 05622ca.

📒 Files selected for processing (8)
  • web/packages/studio/src/routes/AnonymizerBuilderRoute/apiErrors.test.ts
  • web/packages/studio/src/routes/AnonymizerBuilderRoute/apiErrors.ts
  • web/packages/studio/src/routes/AnonymizerBuilderRoute/components/GenerationSection.tsx
  • web/packages/studio/src/routes/AnonymizerBuilderRoute/components/StrategyParamsSection.tsx
  • web/packages/studio/src/routes/AnonymizerBuilderRoute/constants.ts
  • web/packages/studio/src/routes/AnonymizerBuilderRoute/index.tsx
  • web/packages/studio/src/routes/AnonymizerBuilderRoute/schema.test.ts
  • web/packages/studio/src/routes/AnonymizerBuilderRoute/schema.ts

@github-actions

github-actions Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor
Suite Lines Covered Line Rate Branch Rate
Unit Tests 27157/34869 77.9% 62.1%
Integration Tests 15969/33581 47.5% 20.0%

@marcusds
marcusds enabled auto-merge July 24, 2026 23:21
marcusds added 5 commits July 24, 2026 16:22
Unlock Redact/Annotate/Hash in the strategy select (Rewrite stays locked)
and add their parameter fields (format templates, normalize checkbox,
hash algorithm + digest length). Wire params into config.replace,
omitting empty templates.

Surface backend validation 422s inline: parse the pydantic detail and
map each loc to its form field via a reusable helper, falling back to the
banner for unmapped errors.

Signed-off-by: mschwab <mschwab@nvidia.com>
…[ASTD-333]

Signed-off-by: mschwab <mschwab@nvidia.com>
Preflight health checks hammered the models and blew provider rate limits
(e.g. nvidia/gliner-pii) before the workflow ran. Set skip_health_check
on each model_config so the actual anonymization calls carry the budget.

Signed-off-by: mschwab <mschwab@nvidia.com>
Derive HashAlgorithmOption, the dropdown options, and the zod enum from
one HASH_ALGORITHM_VALUES tuple so a new algorithm can't be added in one
place and silently fail validation in the other. Mark anonymizer
apiErrors interface fields readonly.

Signed-off-by: mschwab <mschwab@nvidia.com>
@marcusds
marcusds force-pushed the astd-333-anonymizer-strategy-params/mschwab branch from 77764f3 to d0ed611 Compare July 24, 2026 23:25
@marcusds
marcusds added this pull request to the merge queue Jul 24, 2026
Merged via the queue into main with commit 3787c34 Jul 24, 2026
58 checks passed
@marcusds
marcusds deleted the astd-333-anonymizer-strategy-params/mschwab branch July 24, 2026 23:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants