Skip to content

feat(studio): add guardrail detail tabs with structured Configuration viewer and draft editing - #830

Merged
aray12 merged 3 commits into
mainfrom
astd-236-guardrails-checks-tab
Jul 28, 2026
Merged

feat(studio): add guardrail detail tabs with structured Configuration viewer and draft editing#830
aray12 merged 3 commits into
mainfrom
astd-236-guardrails-checks-tab

Conversation

@aray12

@aray12 aray12 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Introduce the guardrail detail tab shell and a structured Configuration tab
that renders the full RailsConfig schema (pipeline stages, detectors,
models/prompting, behavior) instead of a raw JSON dump. Includes a
flow-recognition registry and detector scope derivation.

Editing & the guardrail draft

The General section is now editable — General instruction (mapped to
the first general entry in instructions[]) and Sample conversation
(sample_conversation) are free-text fields that hide their underlying schema.

Edits flow into a page-level guardrail draft rather than saving immediately:

  • The draft is persisted to local storage, keyed per workspace/config, so
    in-progress edits survive reloads.
  • Save Guardrail / Reset header actions appear only once the draft
    diverges from the server config (isDirty); editing a field back to its
    server value clears the draft entirely.
  • A draft branched from a stale server version (older updated_at) is
    discarded automatically, so edits are never PATCHed on top of a config that
    changed underneath.
  • Saving PATCHes the config, invalidates the query to refetch, clears the
    draft, and toasts.

The remaining sections (pipeline, detectors, models & prompting, behavior, raw
config) stay read-only for now.

Signed-off-by: Alex Ray alray@nvidia.com

Summary by CodeRabbit

  • New Features
    • Added a dedicated Guardrail Configuration tab for editing and viewing configuration with Overview, Pipeline, Detectors, Models & prompting, Behavior, and Raw JSON sections.
    • Introduced Save and Reset actions with draft editing support and automatic navigation from guardrail details to Configuration.
  • Bug Fixes
    • Improved guardrail config editing reliability by updating the server and refreshing the displayed results after saves.
  • Tests
    • Expanded Jest coverage for the configuration UI sections, flow recognition, detector summaries, and instruction editing behavior.

@aray12
aray12 requested review from a team as code owners July 21, 2026 19:53
@github-actions github-actions Bot added the feat label Jul 21, 2026
@aray12

aray12 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

@aray12
aray12 force-pushed the astd-236-guardrails-checks-ui branch from 34a76bf to a6b221b Compare July 21, 2026 20:41
@aray12
aray12 force-pushed the astd-236-guardrails-checks-tab branch from 5026a87 to e86c1ac Compare July 21, 2026 20:41
Base automatically changed from astd-236-guardrails-checks-ui to main July 23, 2026 20:20
@aray12
aray12 force-pushed the astd-236-guardrails-checks-tab branch from e86c1ac to 2f33320 Compare July 24, 2026 01:41
@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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 14e9723e-7c0b-4ab8-b8f3-3efc66eebe8c

📥 Commits

Reviewing files that changed from the base of the PR and between a869d48 and c5d8526.

📒 Files selected for processing (3)
  • web/packages/studio/src/routes/guardrails/GuardrailForm/GuardrailFormProvider.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailForm/formModel.test.ts
  • web/packages/studio/src/routes/guardrails/GuardrailForm/formModel.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • web/packages/studio/src/routes/guardrails/GuardrailForm/formModel.ts
  • web/packages/studio/src/routes/guardrails/GuardrailForm/GuardrailFormProvider.tsx

📝 Walkthrough

Walkthrough

Guardrail details now provide nested configuration routing, structured configuration panels, editable general fields, local drafts, reset/save actions, and PATCH-based updates with test coverage for routing, form behavior, flow recognition, detectors, and rendered sections.

Changes

Guardrail configuration workflow

Layer / File(s) Summary
Nested routing and draft editing
web/packages/studio/src/constants/routes.ts, web/packages/studio/src/routes/groups/guardrailsRoutes.tsx, web/packages/studio/src/routes/guardrails/GuardrailDetailRoute/*, web/packages/studio/src/routes/guardrails/GuardrailForm/*, web/packages/studio/src/routes/utils.ts, web/packages/studio/src/mocks/handlers/guardrails.ts
Guardrail details now redirect to a configuration child route, provide React Hook Form state, persist versioned drafts locally, and save or reset edits through the guardrail update endpoint.
Configuration interpretation helpers
web/packages/studio/src/routes/guardrails/GuardrailConfigTab/types.ts, flowRegistry.*, instructions.*, detectors.*
Flow names, general instructions, detector metadata, scopes, and detector settings are normalized into display-ready values with masking for secret-like fields.
Structured configuration panels
web/packages/studio/src/routes/guardrails/GuardrailConfigTab/*Section.tsx, configPrimitives.tsx, index.tsx, sections.test.tsx
The configuration tab renders overview, general, pipeline, detector, model, behavior, and raw JSON sections, with conditional content and shared field, badge, and empty-state primitives.

Suggested reviewers: htolentino-nvidia, marcusds, steramae-nvidia

🚥 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 accurately summarizes the main change: new guardrail detail tabs, a structured Configuration viewer, and draft editing.
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-236-guardrails-checks-tab

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: 3

🧹 Nitpick comments (4)
web/packages/studio/src/routes/guardrails/GuardrailConfigTab/DraftTextAreaField.tsx (1)

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

Make the prop contract readonly.

Mark DraftTextAreaFieldProps members readonly. As per coding guidelines, use readonly for immutable properties in TypeScript interfaces and types.

🤖 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/guardrails/GuardrailConfigTab/DraftTextAreaField.tsx`
around lines 7 - 15, Update the DraftTextAreaFieldProps interface so every
property, including label, description, placeholder, value, and onChange, is
marked readonly. Preserve the existing property types and optionality.

Source: Coding guidelines

web/packages/studio/src/routes/guardrails/GuardrailDraft/useGuardrailDraft.ts (2)

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

Declare the hook return type.

Expose the non-null context value as the exported hook contract. As per coding guidelines, exported public APIs require explicit return types.

🤖 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/guardrails/GuardrailDraft/useGuardrailDraft.ts`
around lines 7 - 13, Update the exported useGuardrailDraft hook to declare an
explicit return type matching the non-null context value returned after the
GuardrailDraftContext check. Preserve the existing provider validation and
return behavior.

Source: Coding guidelines


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

Keep external imports before internal imports.

  • web/packages/studio/src/routes/guardrails/GuardrailDraft/useGuardrailDraft.ts#L4-L5: move the React import before the internal context import.
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/GeneralSection.tsx#L4-L12: place lucide-react and React imports before @studio imports.
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/LlmSection.tsx#L4-L22: place lucide-react and React imports before @studio imports.
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/BehaviorSection.tsx#L4-L9: place lucide-react and React imports before @studio imports.
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/index.tsx#L4-L17: place lucide-react and React imports before @studio imports.

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/guardrails/GuardrailDraft/useGuardrailDraft.ts`
around lines 4 - 5, Reorder imports so external libraries precede internal
`@studio` modules: in
web/packages/studio/src/routes/guardrails/GuardrailDraft/useGuardrailDraft.ts
lines 4-5, move the React import before GuardrailDraftContext; apply the same
ordering in
web/packages/studio/src/routes/guardrails/GuardrailConfigTab/GeneralSection.tsx
lines 4-12, LlmSection.tsx lines 4-22, BehaviorSection.tsx lines 4-9, and
index.tsx lines 4-17, placing lucide-react and React imports before `@studio`
imports.

Source: Coding guidelines

web/packages/studio/src/routes/guardrails/GuardrailConfigTab/RawConfigSection.tsx (1)

20-30: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Defer raw JSON generation until expanded.

JSON.stringify runs on every draft update even while collapsed. Since GuardrailConfigTab always mounts this section and textarea edits update the draft per keystroke, lazily mount or serialize the raw body only when the accordion is open.

🤖 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/guardrails/GuardrailConfigTab/RawConfigSection.tsx`
around lines 20 - 30, Update RawConfigSection so JSON.stringify(data, null, 2)
is evaluated only after the raw-config AccordionItem is expanded, rather than on
every draft update while collapsed. Use the accordion’s existing open-state
mechanism to conditionally render or lazily compute the pre content, preserving
the current JSON display when expanded.
🤖 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/mocks/handlers/guardrails.ts`:
- Around line 73-81: Update the PATCH handler for guardrail configs to merge the
parsed request body into the matched entry in mockGuardrailConfigs before
returning the response. Preserve the 404 behavior for unknown names, and ensure
subsequent GET/refetch requests observe the persisted merged configuration.

In
`@web/packages/studio/src/routes/guardrails/GuardrailConfigTab/BehaviorSection.tsx`:
- Around line 46-47: Update hasBehaviorContent to base visibility on content
that the BehaviorSection actually renders: count behavior fields and only treat
tracing as present when it produces rendered tracing fields or a badge. Ensure
empty tracing objects and disabled enable_content_capture values do not make the
behavior panel appear unless their disabled state is explicitly rendered.

In `@web/packages/studio/src/routes/guardrails/GuardrailConfigTab/detectors.ts`:
- Around line 116-120: Update SECRET_KEY and formatScalar so secret-bearing keys
with snake_case prefixes or suffixes, including nim_api_key, hf_token, and
access_token, are masked while existing exact-name matches remain supported. Add
regression cases covering these prefixed/suffixed keys and verify non-secret
keys remain rendered normally.

---

Nitpick comments:
In
`@web/packages/studio/src/routes/guardrails/GuardrailConfigTab/DraftTextAreaField.tsx`:
- Around line 7-15: Update the DraftTextAreaFieldProps interface so every
property, including label, description, placeholder, value, and onChange, is
marked readonly. Preserve the existing property types and optionality.

In
`@web/packages/studio/src/routes/guardrails/GuardrailConfigTab/RawConfigSection.tsx`:
- Around line 20-30: Update RawConfigSection so JSON.stringify(data, null, 2) is
evaluated only after the raw-config AccordionItem is expanded, rather than on
every draft update while collapsed. Use the accordion’s existing open-state
mechanism to conditionally render or lazily compute the pre content, preserving
the current JSON display when expanded.

In
`@web/packages/studio/src/routes/guardrails/GuardrailDraft/useGuardrailDraft.ts`:
- Around line 7-13: Update the exported useGuardrailDraft hook to declare an
explicit return type matching the non-null context value returned after the
GuardrailDraftContext check. Preserve the existing provider validation and
return behavior.
- Around line 4-5: Reorder imports so external libraries precede internal
`@studio` modules: in
web/packages/studio/src/routes/guardrails/GuardrailDraft/useGuardrailDraft.ts
lines 4-5, move the React import before GuardrailDraftContext; apply the same
ordering in
web/packages/studio/src/routes/guardrails/GuardrailConfigTab/GeneralSection.tsx
lines 4-12, LlmSection.tsx lines 4-22, BehaviorSection.tsx lines 4-9, and
index.tsx lines 4-17, placing lucide-react and React imports before `@studio`
imports.
🪄 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: c6632b2c-01dd-469f-a7e5-6ecd64fdf81f

📥 Commits

Reviewing files that changed from the base of the PR and between 97d5e6c and 2f33320.

📒 Files selected for processing (27)
  • web/packages/studio/src/constants/routes.ts
  • web/packages/studio/src/mocks/handlers/guardrails.ts
  • web/packages/studio/src/routes/groups/guardrailsRoutes.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/BehaviorSection.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/DetectorsSection.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/DraftTextAreaField.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/GeneralSection.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/LlmSection.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/PipelineSection.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/RawConfigSection.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/configPrimitives.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/detectors.test.ts
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/detectors.ts
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/flowRegistry.test.ts
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/flowRegistry.ts
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/index.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/instructions.test.ts
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/instructions.ts
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/sections.test.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/types.ts
  • web/packages/studio/src/routes/guardrails/GuardrailDetailRoute/index.test.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailDetailRoute/index.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailDraft/GuardrailDraftProvider.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailDraft/GuardrailHeaderActions.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailDraft/context.ts
  • web/packages/studio/src/routes/guardrails/GuardrailDraft/useGuardrailDraft.ts
  • web/packages/studio/src/routes/utils.ts

Comment thread web/packages/studio/src/mocks/handlers/guardrails.ts
Comment thread web/packages/studio/src/routes/guardrails/GuardrailConfigTab/BehaviorSection.tsx Outdated
Comment thread web/packages/studio/src/routes/guardrails/GuardrailConfigTab/detectors.ts Outdated
@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor
Suite Lines Covered Line Rate Branch Rate
Unit Tests 27292/35040 77.9% 62.1%
Integration Tests 16022/33752 47.5% 19.9%

…viewer

Introduce the guardrail detail tab shell and a structured, read-only
Configuration tab that renders the full RailsConfig schema (pipeline
stages, detectors, models/prompting, behavior) instead of a raw JSON dump.
Includes a flow-recognition registry and detector scope derivation.

Signed-off-by: Alex Ray <alray@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/guardrails/GuardrailConfigTab/sections.test.tsx (1)

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

Avoid casting incomplete objects to RailsConfigOutput.

Lines 72, 82, and 92 bypass the schema with as RailsConfigOutput, so future required-field changes can compile while tests continue using invalid fixtures. Create one valid typed config fixture/factory and override only tracing.

🤖 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/guardrails/GuardrailConfigTab/sections.test.tsx`
around lines 68 - 97, Replace the incomplete object casts in the BehaviorSection
tests with a single valid typed RailsConfigOutput fixture or factory, then
override only its tracing field for each scenario. Update all three test cases
to use this fixture while preserving their existing tracing-specific assertions.

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/guardrails/GuardrailConfigTab/sections.test.tsx`:
- Around line 68-97: Replace the incomplete object casts in the BehaviorSection
tests with a single valid typed RailsConfigOutput fixture or factory, then
override only its tracing field for each scenario. Update all three test cases
to use this fixture while preserving their existing tracing-specific assertions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 4a5be4c4-4906-4fa5-9d39-38e61bdb0a00

📥 Commits

Reviewing files that changed from the base of the PR and between 2f33320 and 67367fa.

📒 Files selected for processing (5)
  • web/packages/studio/src/mocks/handlers/guardrails.ts
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/BehaviorSection.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/detectors.test.ts
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/detectors.ts
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/sections.test.tsx
🚧 Files skipped from review as they are similar to previous changes (4)
  • web/packages/studio/src/mocks/handlers/guardrails.ts
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/detectors.test.ts
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/BehaviorSection.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/detectors.ts

@aray12 aray12 changed the title feat(studio): add guardrail detail tabs with read-only Configuration viewer feat(studio): add guardrail detail tabs with structured Configuration viewer and draft editing Jul 27, 2026

@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/guardrails/GuardrailConfigTab/GeneralSection.tsx (1)

4-11: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Group external imports before internal aliases.

Move lucide-react and react above the @studio/... imports. As per coding guidelines, group imports as external libraries, then internal modules.

🤖 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/guardrails/GuardrailConfigTab/GeneralSection.tsx`
around lines 4 - 11, Reorder imports in GeneralSection.tsx so external packages,
including lucide-react and react, appear before the internal `@studio/`...
aliases; leave the imported symbols and functionality unchanged.

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/guardrails/GuardrailConfigTab/GeneralSection.tsx`:
- Around line 4-11: Reorder imports in GeneralSection.tsx so external packages,
including lucide-react and react, appear before the internal `@studio/`...
aliases; leave the imported symbols and functionality unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 092c29a3-ab61-43bc-b950-c6eb99eae1aa

📥 Commits

Reviewing files that changed from the base of the PR and between 67367fa and 41d3173.

📒 Files selected for processing (1)
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/GeneralSection.tsx

- persist PATCH body in the guardrails mock so save-then-refetch observes edits
- broaden secret-key masking to prefixed/suffixed keys (nim_api_key, hf_token)
- base behavior-panel visibility on rendered content so empty tracing hides it

Adds regression tests for secret masking and empty behavior panels.

Signed-off-by: Alex Ray <alray@nvidia.com>
@aray12
aray12 force-pushed the astd-236-guardrails-checks-tab branch from 41d3173 to a869d48 Compare July 27, 2026 21:39

@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: 2

🧹 Nitpick comments (2)
web/packages/studio/src/routes/guardrails/GuardrailForm/useGuardrailForm.ts (1)

7-13: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Add explicit return type for this public hook.

As per coding guidelines, web/**/*.{ts,tsx}: "Use explicit return types for public APIs and complex functions in TypeScript." useGuardrailForm is exported without one.

-export const useGuardrailForm = () => {
+export const useGuardrailForm = (): GuardrailFormContextValue => {
🤖 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/guardrails/GuardrailForm/useGuardrailForm.ts`
around lines 7 - 13, Add an explicit TypeScript return type to the exported
useGuardrailForm hook, using the type of GuardrailFormContext so its current
context return value and provider error behavior remain unchanged.

Source: Coding guidelines

web/packages/studio/src/routes/guardrails/GuardrailForm/GuardrailFormProvider.tsx (1)

67-76: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Consider debouncing draft persistence.

Draft is written to localStorage on every values change while dirty (i.e., every keystroke). Fine for small drafts; a debounce would avoid repeated stringify/write on the input hot path for long instruction/sample-conversation text.

🤖 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/guardrails/GuardrailForm/GuardrailFormProvider.tsx`
around lines 67 - 76, Debounce draft persistence in the useEffect that watches
isDirty and values, so setStored is not called on every keystroke while editing
long fields. Preserve the existing clearStored behavior when the form is no
longer dirty, and cancel or clean up the pending debounce on dependency changes
or unmount.
🤖 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/guardrails/GuardrailForm/formModel.ts`:
- Around line 41-52: Update applyFormToConfig so the instructions field uses the
result from setGeneralInstruction directly, preserving an empty array when the
user removes the sole general instruction; do not fall back to base.instructions
for an empty computed list.

In
`@web/packages/studio/src/routes/guardrails/GuardrailForm/GuardrailFormProvider.tsx`:
- Around line 82-99: Separate the successful updateConfig call from cache
invalidation in the save handler created by GuardrailFormProvider. Treat
updateConfig success as the save completion: clearStored, reset the form, and
show the success toast even if invalidateQueries fails; handle invalidation
failure independently without reporting the PATCH as a save failure.

---

Nitpick comments:
In
`@web/packages/studio/src/routes/guardrails/GuardrailForm/GuardrailFormProvider.tsx`:
- Around line 67-76: Debounce draft persistence in the useEffect that watches
isDirty and values, so setStored is not called on every keystroke while editing
long fields. Preserve the existing clearStored behavior when the form is no
longer dirty, and cancel or clean up the pending debounce on dependency changes
or unmount.

In `@web/packages/studio/src/routes/guardrails/GuardrailForm/useGuardrailForm.ts`:
- Around line 7-13: Add an explicit TypeScript return type to the exported
useGuardrailForm hook, using the type of GuardrailFormContext so its current
context return value and provider error behavior remain unchanged.
🪄 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: 434e0841-cea4-429d-a10d-ca378580628b

📥 Commits

Reviewing files that changed from the base of the PR and between 41d3173 and a869d48.

📒 Files selected for processing (27)
  • web/packages/studio/src/constants/routes.ts
  • web/packages/studio/src/mocks/handlers/guardrails.ts
  • web/packages/studio/src/routes/groups/guardrailsRoutes.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/BehaviorSection.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/DetectorsSection.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/GeneralSection.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/LlmSection.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/PipelineSection.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/RawConfigSection.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/configPrimitives.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/detectors.test.ts
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/detectors.ts
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/flowRegistry.test.ts
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/flowRegistry.ts
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/index.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/instructions.test.ts
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/instructions.ts
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/sections.test.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/types.ts
  • web/packages/studio/src/routes/guardrails/GuardrailDetailRoute/index.test.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailDetailRoute/index.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailForm/GuardrailFormProvider.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailForm/GuardrailHeaderActions.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailForm/context.ts
  • web/packages/studio/src/routes/guardrails/GuardrailForm/formModel.ts
  • web/packages/studio/src/routes/guardrails/GuardrailForm/useGuardrailForm.ts
  • web/packages/studio/src/routes/utils.ts
🚧 Files skipped from review as they are similar to previous changes (19)
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/RawConfigSection.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/types.ts
  • web/packages/studio/src/routes/utils.ts
  • web/packages/studio/src/mocks/handlers/guardrails.ts
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/DetectorsSection.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/BehaviorSection.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/sections.test.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/detectors.test.ts
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/configPrimitives.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/flowRegistry.ts
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/PipelineSection.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/instructions.ts
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/flowRegistry.test.ts
  • web/packages/studio/src/routes/groups/guardrailsRoutes.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/LlmSection.tsx
  • web/packages/studio/src/constants/routes.ts
  • web/packages/studio/src/routes/guardrails/GuardrailConfigTab/instructions.test.ts
  • web/packages/studio/src/routes/guardrails/GuardrailDetailRoute/index.test.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailDetailRoute/index.tsx

- applyFormToConfig: persist removal of the sole general instruction as an
  empty list instead of falling back to the still-populated base instructions.
- GuardrailFormProvider.save: treat the PATCH as the save completion —
  clear the draft, reset the form, and toast success even if the follow-up
  cache invalidation fails; handle that refetch failure silently.

Adds formModel unit tests covering the instruction edge cases.

Signed-off-by: Alex Ray <alray@nvidia.com>
@aray12
aray12 enabled auto-merge July 27, 2026 22:15
@aray12
aray12 added this pull request to the merge queue Jul 28, 2026
Merged via the queue into main with commit 1739e3a Jul 28, 2026
60 checks passed
@aray12
aray12 deleted the astd-236-guardrails-checks-tab branch July 28, 2026 20:06
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