Skip to content

feat(studio): Anonymizer Rewrite strategy params [ASTD-334] - #904

Merged
marcusds merged 4 commits into
mainfrom
astd-334-anonymizer-rewrite-params/mschwab
Jul 27, 2026
Merged

feat(studio): Anonymizer Rewrite strategy params [ASTD-334]#904
marcusds merged 4 commits into
mainfrom
astd-334-anonymizer-rewrite-params/mschwab

Conversation

@marcusds

@marcusds marcusds commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Closes ASTD-334.

Unlocks Rewrite in the anonymization strategy select and adds its parameter UI, the last of the five strategies. Follows #898 (ASTD-333).

What's here

New RewriteParamsSection, rendered below the strategy dropdown when Rewrite is selected:

Field Control Maps to
Privacy Goal Segmented (Default / Custom)
Protect / Preserve Textareas, shown only in Custom rewrite.privacy_goal
LLM Instructions Textarea rewrite.instructions
Risk Tolerance Slider, Minimal → High rewrite.risk_tolerance
Max Repair Rounds Number, min 0 rewrite.max_repair_iterations
Strict Entity Protection Checkbox rewrite.strict_entity_protection

Default mode omits privacy_goal entirely so the server auto-populates it, rather than sending empty strings that would 422. Per the ASTD-333 precedent there are no client-side length rules on protect/preserve — the backend's 422s map to inline field errors, and apiErrors.ts now covers the rewrite locs.

Notable decisions

Risk Tolerance uses the raw KUI Slider, not ControlledSlider. ControlledSlider writes a number into the form field unconditionally, which would clobber the enum. Raw Slider + useController keeps riskTolerance as 'minimal' | 'low' | 'moderate' | 'high' in form state with the index mapping local to the component; stepFormatFn renders the tick labels.

RISK_TOLERANCE_LABELS is Record<RiskTolerance, string> — exhaustive against the SDK enum, so a new preset fails the build rather than silently rendering without a label.

Fix: rewrite jobs must map the replacement generator

Rewrite jobs were failing preflight with:

InvalidConfigError: Selected model aliases not found in model pool:
replace.replacement_generator='gpt-oss-120b'. Known aliases: ['model-1']

Rewrite reuses the replacement generator internally, so the library validates that role for rewrite too:

# anonymizer/interface/anonymizer.py:648
check_substitute=isinstance(config.replace, Substitute) or config.rewrite is not None,

We were sending selected_models with only detection + rewrite, so the server kept its own default (default_model_configs/replace.yamlgpt-oss-120b), which isn't in the pool we send. activeRolesForStrategy('rewrite') now includes REPLACE_ROLE and the builder emits selected_models.replace. Verified by calling validate_model_alias_references directly with both payload shapes — old fails with the exact error above, new passes.

Drive-by fixes

Both pre-existing from ASTD-327, surfaced while testing this form:

  • Select triggers rendered raw values (rewrite, dataset, sha256). KUI's SelectEntry is { children, value }label isn't a prop, so it was dropped and the trigger fell back to the value. Fixed across the three option lists in this route. Typecheck didn't catch it because the extra key was structurally compatible.
  • Cancel / Full Run floated over the form on scroll. overflow-auto was on the Panel root, but .nv-panel-root is the flex column holding the footer, so the footer scrolled with the content. Moved the scroll to the content slot (flex-1 min-h-0 overflow-auto).

Screenshots

01-rewrite-default 02-rewrite-custom-privacy-goal 04-footer-pinned-on-scroll

Testing

  • 21 unit tests pass (5 new: rewrite config shape, privacy-goal modes, instruction trimming, param carry-through, replacement-generator mapping)
  • typecheck, eslint, prettier clean
  • Verified in a running Studio against a live platform: form renders, Custom reveals protect/preserve, Model Settings resolves all rewrite roles including the new Replacement Generator, footer stays pinned through scroll

Out of scope

ASTD-336 filed separately: the Entity Detector role falls back to a general LLM when the workspace has no GLiNER model, and the library injects GLiNER-only params into whatever that role points at, so jobs die at detection with a 400. Pre-existing and affects all five strategies.

Summary by CodeRabbit

  • New Features

    • Added rewrite strategy support with privacy goals, instructions, risk tolerance, repair rounds, and strict entity protection settings.
    • Added a two-tab anonymizer builder with Source and Model Settings sections.
    • Improved automatic model selection for required anonymizer roles.
    • Rewrite configurations are now included when submitting jobs.
  • Bug Fixes

    • Rewrite-related API validation errors now map to the appropriate form fields.
    • Improved selected-model handling for rewrite and substitute strategies.

@marcusds
marcusds requested review from a team as code owners July 27, 2026 16:13
@github-actions github-actions Bot added the feat label Jul 27, 2026
Unlock Rewrite in the anonymization strategy select and add its parameter
UI: privacy goal (default/custom with protect + preserve), LLM
instructions, risk tolerance, max repair rounds, and strict entity
protection, mapped onto config.rewrite.

Rewrite reuses the replacement generator internally, so the backend
validates replace.replacement_generator for rewrite jobs too. Without it
the request kept the library default alias and preflight failed with
"Selected model aliases not found in model pool". Map the replace role
for rewrite as well.

Also fixes two pre-existing issues surfaced while testing this form:
select items carry `children`, not `label`, so triggers were rendering
raw values ("rewrite", "dataset"); and the panel's scroll lived on the
root, which swept the footer into the scrolling box and floated the
Cancel/Full Run buttons over the form.

Signed-off-by: mschwab <mschwab@nvidia.com>
@marcusds
marcusds force-pushed the astd-334-anonymizer-rewrite-params/mschwab branch from f418d15 to ecf3d1f Compare July 27, 2026 16:17
@coderabbitai

coderabbitai Bot commented Jul 27, 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

The anonymizer builder now supports rewrite-specific configuration, request serialization, model initialization, tabbed form rendering, and nested rewrite API error mapping.

Changes

Rewrite builder support

Layer / File(s) Summary
Rewrite form and request contract
web/packages/studio/src/routes/AnonymizerBuilderRoute/constants.ts, schema.ts, schema.test.ts
Adds rewrite defaults, validation, privacy and risk settings, populated rewrite request construction, strategy-dependent selected models, and expanded tests.
Role model loading and defaults
web/packages/studio/src/routes/AnonymizerBuilderRoute/useAnonymizerModels.ts, useDefaultRoleModels.ts, components/ModelSettingsSection.tsx
Centralizes provider model loading, model application, role coverage, and default role-model seeding.
Rewrite parameter UI and builder form
web/packages/studio/src/routes/AnonymizerBuilderRoute/components/*, index.tsx
Adds rewrite controls, exposes rewrite in strategy selection, introduces the tabbed builder form, and delegates route rendering to it.
Rewrite validation error mapping
web/packages/studio/src/routes/AnonymizerBuilderRoute/apiErrors.ts, apiErrors.test.ts
Maps nested rewrite API locations to privacy and rewrite form fields and tests the mappings.

Sequence Diagram(s)

sequenceDiagram
  participant AnonymizerBuilderForm
  participant buildAnonymizerJobRequest
  participant useAnonymizerCreateRunJob
  participant AnonymizerBuilderRoute
  AnonymizerBuilderForm->>buildAnonymizerJobRequest: submit rewrite form data
  AnonymizerBuilderForm->>useAnonymizerCreateRunJob: create run job
  useAnonymizerCreateRunJob->>AnonymizerBuilderRoute: return job result
  AnonymizerBuilderRoute->>AnonymizerBuilderRoute: navigate to job or workspace
Loading

Possibly related PRs

Suggested reviewers: steramae-nvidia, aray12, nv-odrulea

🚥 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 rewrite strategy parameters for the Studio anonymizer.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch astd-334-anonymizer-rewrite-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.

🧹 Nitpick comments (1)
web/packages/studio/src/routes/AnonymizerBuilderRoute/components/RewriteParamsSection.tsx (1)

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

Use a type-only React import.

Change to import type { FC } from 'react';. As per coding guidelines, “Use import type for type-only imports in TypeScript.”

🤖 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/components/RewriteParamsSection.tsx`
at line 17, Update the React import in RewriteParamsSection.tsx to use a
type-only import for FC, preserving the existing type usage without importing a
runtime value.

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.

Nitpick comments:
In
`@web/packages/studio/src/routes/AnonymizerBuilderRoute/components/RewriteParamsSection.tsx`:
- Line 17: Update the React import in RewriteParamsSection.tsx to use a
type-only import for FC, preserving the existing type usage without importing a
runtime value.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 0254d7a9-e9cc-41bf-8fca-3ab024419824

📥 Commits

Reviewing files that changed from the base of the PR and between dae9035 and f418d15.

📒 Files selected for processing (9)
  • 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/RewriteParamsSection.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

Move the risk-tolerance step formatter and the panel attributes object to
module scope so they keep referential identity across renders instead of
being rebuilt each time.

Signed-off-by: mschwab <mschwab@nvidia.com>
@github-actions

github-actions Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor
Suite Lines Covered Line Rate Branch Rate
Unit Tests 27236/34958 77.9% 62.2%
Integration Tests 16000/33670 47.5% 19.9%

Extract the workspace model list and the per-role defaulting effect into
useAnonymizerModels/useDefaultRoleModels, and run the defaulting from a
RoleModelDefaults child of the form provider. Previously the defaults were
seeded by an effect inside ModelSettingsSection, so they only applied
because that tab stays mounted; ModelSettingsSection is now pure render.

Groundwork for wrapping the tab panels in <Activity>, which is not safe
here yet: react-hook-form's useWatch subscribes in an effect, and Activity
tears down effects while hidden, so the inactive tab renders stale values.

Signed-off-by: mschwab <mschwab@nvidia.com>

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

🧹 Nitpick comments (1)
web/packages/studio/src/routes/AnonymizerBuilderRoute/components/ModelSettingsSection.tsx (1)

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

Import FC as a type.

  • web/packages/studio/src/routes/AnonymizerBuilderRoute/components/ModelSettingsSection.tsx#L14-L14: split FC into import type { FC } from 'react'.
  • web/packages/studio/src/routes/AnonymizerBuilderRoute/components/RoleModelDefaults.tsx#L5-L5: change to import type { FC } from 'react'.

As per coding guidelines, “Use import type for type-only imports in TypeScript.”

🤖 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/components/ModelSettingsSection.tsx`
at line 14, Update the React imports in ModelSettingsSection.tsx (line 14) and
RoleModelDefaults.tsx (line 5) to import FC using import type, keeping any
runtime React imports separate.

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.

Nitpick comments:
In
`@web/packages/studio/src/routes/AnonymizerBuilderRoute/components/ModelSettingsSection.tsx`:
- Line 14: Update the React imports in ModelSettingsSection.tsx (line 14) and
RoleModelDefaults.tsx (line 5) to import FC using import type, keeping any
runtime React imports separate.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: e07b8bc4-c8ce-4531-938d-90f6fcbbd290

📥 Commits

Reviewing files that changed from the base of the PR and between fbbd8ca and a97ecb4.

📒 Files selected for processing (5)
  • web/packages/studio/src/routes/AnonymizerBuilderRoute/components/ModelSettingsSection.tsx
  • web/packages/studio/src/routes/AnonymizerBuilderRoute/components/RoleModelDefaults.tsx
  • web/packages/studio/src/routes/AnonymizerBuilderRoute/index.tsx
  • web/packages/studio/src/routes/AnonymizerBuilderRoute/useAnonymizerModels.ts
  • web/packages/studio/src/routes/AnonymizerBuilderRoute/useDefaultRoleModels.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • web/packages/studio/src/routes/AnonymizerBuilderRoute/index.tsx

@marcusds marcusds changed the title feat(studio): Rewrite strategy params [ASTD-334] feat(studio): Anonymizer Rewrite strategy params [ASTD-334] Jul 27, 2026
Comment thread web/packages/studio/src/routes/AnonymizerBuilderRoute/index.tsx Outdated
Move the form UI, tab state, and submit handling out of the route into
AnonymizerBuilderForm, rendered under FormProvider. The component can now
call useDefaultRoleModels directly, so the RoleModelDefaults null-render
shim that only existed to reach form context is gone.

The route's separate useModelsListProviders call was identical to the one
inside useAnonymizerModels, so the submit button's loading state now comes
from useDefaultRoleModels instead.

Also import FC with the inline type modifier in the touched files.

Signed-off-by: mschwab <mschwab@nvidia.com>

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

🧹 Nitpick comments (1)
web/packages/studio/src/routes/AnonymizerBuilderRoute/components/AnonymizerBuilderForm.tsx (1)

16-32: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Group external imports before internal aliases.

  • web/packages/studio/src/routes/AnonymizerBuilderRoute/components/AnonymizerBuilderForm.tsx#L16-L32: move React, react-hook-form, and react-router-dom imports before @studio/*.
  • web/packages/studio/src/routes/AnonymizerBuilderRoute/index.tsx#L8-L14: keep React and react-hook-form imports in the external import group before @studio/*.

As per coding guidelines, “Group imports: external libraries, internal modules, relative imports in TypeScript.”

🤖 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/components/AnonymizerBuilderForm.tsx`
around lines 16 - 32, Group external imports before internal aliases: in
web/packages/studio/src/routes/AnonymizerBuilderRoute/components/AnonymizerBuilderForm.tsx
lines 16-32, move React, react-hook-form, and react-router-dom imports above the
`@studio` imports; apply the same ordering in
web/packages/studio/src/routes/AnonymizerBuilderRoute/index.tsx lines 8-14 by
placing React and react-hook-form imports before `@studio` imports.

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.

Nitpick comments:
In
`@web/packages/studio/src/routes/AnonymizerBuilderRoute/components/AnonymizerBuilderForm.tsx`:
- Around line 16-32: Group external imports before internal aliases: in
web/packages/studio/src/routes/AnonymizerBuilderRoute/components/AnonymizerBuilderForm.tsx
lines 16-32, move React, react-hook-form, and react-router-dom imports above the
`@studio` imports; apply the same ordering in
web/packages/studio/src/routes/AnonymizerBuilderRoute/index.tsx lines 8-14 by
placing React and react-hook-form imports before `@studio` imports.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 7d813951-1fa8-43fa-a396-4885eae76860

📥 Commits

Reviewing files that changed from the base of the PR and between a97ecb4 and f2f5ffe.

📒 Files selected for processing (4)
  • web/packages/studio/src/routes/AnonymizerBuilderRoute/components/AnonymizerBuilderForm.tsx
  • web/packages/studio/src/routes/AnonymizerBuilderRoute/components/ModelSettingsSection.tsx
  • web/packages/studio/src/routes/AnonymizerBuilderRoute/components/RewriteParamsSection.tsx
  • web/packages/studio/src/routes/AnonymizerBuilderRoute/index.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • web/packages/studio/src/routes/AnonymizerBuilderRoute/components/RewriteParamsSection.tsx
  • web/packages/studio/src/routes/AnonymizerBuilderRoute/components/ModelSettingsSection.tsx

@marcusds
marcusds requested a review from nakolean July 27, 2026 18:52
@marcusds
marcusds added this pull request to the merge queue Jul 27, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 27, 2026
@marcusds
marcusds added this pull request to the merge queue Jul 27, 2026
Merged via the queue into main with commit 206a139 Jul 27, 2026
60 checks passed
@marcusds
marcusds deleted the astd-334-anonymizer-rewrite-params/mschwab branch July 27, 2026 21:24
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.

3 participants