Skip to content

feat(studio): add guardrail Test and Validate tab (checks, runs, detail) - #831

Merged
nakolean merged 3 commits into
mainfrom
astd-236-guardrail-check-details
Aug 3, 2026
Merged

feat(studio): add guardrail Test and Validate tab (checks, runs, detail)#831
nakolean merged 3 commits into
mainfrom
astd-236-guardrail-check-details

Conversation

@aray12

@aray12 aray12 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Add the Test and Validate tab to the guardrail detail view: a checks table
(entity-store-backed test cases) with per-check status and a run action,
a test-case editor, and a check-detail view showing per-rail run verdicts.
Wires the checks and check-detail routes and the second detail tab.

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

Summary by CodeRabbit

  • New Features

    • Added a “Test and Validate” area for guardrails.
    • Create, edit, reorder, duplicate, and remove guardrail test messages.
    • Run all checks and view results with status summaries for Guarded, Allowed, and Not run outcomes.
    • Added chat and read-only JSON views for test cases.
    • Added clear loading, empty, save-error, and operation-status feedback.
  • Style

    • Improved alignment of role badges with message content.

@aray12
aray12 requested review from a team as code owners July 21, 2026 19:53
@aray12

aray12 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

@github-actions github-actions Bot added the feat label Jul 21, 2026
@aray12
aray12 force-pushed the astd-236-guardrails-checks-tab branch from 5026a87 to e86c1ac Compare July 21, 2026 20:41
@aray12
aray12 force-pushed the astd-236-guardrail-check-details branch from a3dc362 to a012ff1 Compare July 21, 2026 20:41
@aray12
aray12 force-pushed the astd-236-guardrails-checks-tab branch 2 times, most recently from 41d3173 to a869d48 Compare July 27, 2026 21:39
@aray12
aray12 force-pushed the astd-236-guardrail-check-details branch from a012ff1 to 439ef39 Compare July 27, 2026 22:01
Base automatically changed from astd-236-guardrails-checks-tab to main July 28, 2026 20:06
aray12 added 2 commits July 31, 2026 10:14
Add the Test and Validate tab to the guardrail detail view: a checks table
(entity-store-backed test cases) with per-check status and a run action,
a test-case editor, and a check-detail view showing per-rail run verdicts.
Wires the checks and check-detail routes and the second detail tab.

Signed-off-by: Alex Ray <alray@nvidia.com>
Signed-off-by: Alex Ray <alray@nvidia.com>
@nakolean
nakolean force-pushed the astd-236-guardrail-check-details branch from 439ef39 to d962340 Compare July 31, 2026 17:30
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

Guardrail checks

Layer / File(s) Summary
Checks route and detail navigation
web/packages/studio/src/constants/routes.ts, web/packages/studio/src/routes/utils.ts, web/packages/studio/src/routes/groups/guardrailsRoutes.tsx, web/packages/studio/src/routes/guardrails/GuardrailDetailRoute/*, web/packages/studio/src/routes/guardrails/GuardrailChecksTab/index.tsx, web/packages/studio/src/mocks/handlers/guardrails.ts, web/packages/studio/src/routes/guardrails/GuardrailChecksTab/index.test.tsx
Adds the checks route, detail navigation tab, lazy loading, configuration and checks queries, mock check data, and route tests.
Test case editing and execution
web/packages/studio/src/routes/guardrails/GuardrailChecksTab/GuardrailTestCasesEditor.tsx, GuardrailTestCard.tsx, GuardrailMessageRow.tsx, web/packages/common/src/components/ChatCompletionInput/index.tsx
Adds message editing, reordering, duplication, deletion, persistence, test creation, run-all actions, and role badge alignment.
Result normalization and results table
web/packages/studio/src/components/dataViews/GuardrailChecksDataView/*, web/packages/studio/src/routes/guardrails/GuardrailChecksTab/GuardrailResultsTable.tsx
Adds message text extraction, latest-run status lookup, status summaries, result badges, and input/output result columns.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant GuardrailDetailRoute
  participant GuardrailChecksTab
  participant EntityStoreAPI
  participant GuardrailTestCasesEditor
  participant GuardrailTestCard
  participant GuardrailResultsTable

  User->>GuardrailDetailRoute: Select Test and Validate
  GuardrailDetailRoute->>GuardrailChecksTab: Navigate to checks route
  GuardrailChecksTab->>EntityStoreAPI: Load configuration and checks
  EntityStoreAPI-->>GuardrailChecksTab: Return configuration and checks
  GuardrailChecksTab->>GuardrailTestCasesEditor: Render loaded checks
  User->>GuardrailTestCard: Edit or run test messages
  GuardrailTestCard->>EntityStoreAPI: Persist test changes
  GuardrailTestCasesEditor->>EntityStoreAPI: Run all checks
  EntityStoreAPI-->>GuardrailResultsTable: Return run statuses
  GuardrailResultsTable-->>User: Display inputs, outputs, and results
Loading

Possibly related PRs

Suggested reviewers: nakolean, 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 clearly describes the main change: adding the guardrail Test and Validate tab with checks, runs, and detail views.
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-guardrail-check-details

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 (2)
web/packages/studio/src/routes/guardrails/GuardrailChecksTab/GuardrailTestCard.tsx (2)

43-45: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Drop the type assertion.

The as GuardrailCheckMessage cast hides any shape mismatch with the API message type. Type the mapper return and let the compiler check it, or narrow role explicitly.

As per coding guidelines: "Use type assertions sparingly. Prefer type guards and narrowing 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/GuardrailChecksTab/GuardrailTestCard.tsx`
around lines 43 - 45, Update toCheckMessages so its mapper returns
GuardrailCheckMessage through contextual typing or an explicit return type,
removing the as GuardrailCheckMessage assertion. If role or content types do not
align, narrow or transform them explicitly so the compiler validates the API
message shape.

Source: Coding guidelines


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

The sync effect never runs.

GuardrailTestCasesEditor renders each card with key={check.id}, so a mounted card never sees a new check.id. The reset is dead code, and check.data.messages in the dependency array is misleading. If you want to ignore server refreshes to protect local drafts, drop the effect and state that in a comment. If you want resync, gate on message content instead.

🤖 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/GuardrailChecksTab/GuardrailTestCard.tsx`
around lines 59 - 66, Update the synchronization logic around
GuardrailTestCard’s lastCheckId and useEffect: because key={check.id} remounts
the card when the ID changes, either remove this dead effect and document that
server refreshes are intentionally ignored to preserve local drafts, or gate
resynchronization on changes to check.data.messages instead of check.id. Keep
form.reset using toFormRows for any synchronization path retained.
🤖 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/GuardrailChecksTab/GuardrailMessageRow.tsx`:
- Around line 92-98: Update GuardrailMessageRow’s focusBody interval lifecycle
by storing the interval id in a ref, clearing any active interval during
component unmount via useEffect cleanup, and adding the required useEffect
import. Preserve the existing focus retry behavior while preventing callbacks
after unmount.

In
`@web/packages/studio/src/routes/guardrails/GuardrailChecksTab/GuardrailTestCard.tsx`:
- Around line 74-87: The persist callback currently reuses the stale
check.db_version during rapid successive saves. Update the GuardrailTestCard
save flow around persist and updateMutation so saves are serialized or queued,
and carry the latest expected_db_version forward from each mutation response
before sending the next patch, preserving all edits without
optimistic-concurrency failures.

In `@web/packages/studio/src/routes/guardrails/GuardrailChecksTab/index.tsx`:
- Around line 30-35: Update the GuardrailChecksTab query-state handling around
isConfigPending, isChecksPending, config, and GuardrailTestCasesEditor to render
the established error state when either config or checks query fails. Do not
fall through to null for config failures, and do not substitute [] for failed
checks data; preserve normal rendering for successful queries. Add tests
covering both query failure paths.

---

Nitpick comments:
In
`@web/packages/studio/src/routes/guardrails/GuardrailChecksTab/GuardrailTestCard.tsx`:
- Around line 43-45: Update toCheckMessages so its mapper returns
GuardrailCheckMessage through contextual typing or an explicit return type,
removing the as GuardrailCheckMessage assertion. If role or content types do not
align, narrow or transform them explicitly so the compiler validates the API
message shape.
- Around line 59-66: Update the synchronization logic around GuardrailTestCard’s
lastCheckId and useEffect: because key={check.id} remounts the card when the ID
changes, either remove this dead effect and document that server refreshes are
intentionally ignored to preserve local drafts, or gate resynchronization on
changes to check.data.messages instead of check.id. Keep form.reset using
toFormRows for any synchronization path retained.
🪄 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: 29204279-6eb5-44fd-85cb-c9bfe1d70c5f

📥 Commits

Reviewing files that changed from the base of the PR and between af0e372 and d962340.

📒 Files selected for processing (13)
  • web/packages/common/src/components/ChatCompletionInput/index.tsx
  • web/packages/studio/src/components/dataViews/GuardrailChecksDataView/checkMessages.ts
  • web/packages/studio/src/components/dataViews/GuardrailChecksDataView/checkStatus.ts
  • web/packages/studio/src/constants/routes.ts
  • web/packages/studio/src/routes/groups/guardrailsRoutes.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailChecksTab/GuardrailMessageRow.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailChecksTab/GuardrailResultsTable.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailChecksTab/GuardrailTestCard.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailChecksTab/GuardrailTestCasesEditor.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailChecksTab/index.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailDetailRoute/index.test.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailDetailRoute/index.tsx
  • web/packages/studio/src/routes/utils.ts

@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor
Suite Lines Covered Line Rate Branch Rate
Unit Tests 29440/37448 78.6% 63.2%
Integration Tests 17378/36166 48.0% 20.5%

Signed-off-by: Nicholas Kolean <nakolean@gmail.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.

Actionable comments posted: 1

🧹 Nitpick comments (2)
web/packages/studio/src/routes/guardrails/GuardrailChecksTab/index.test.tsx (1)

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

Rename routes to TEST_ROUTES.

routes is immutable module-level configuration. Use SCREAMING_SNAKE_CASE for constants. Update renderChecks to pass TEST_ROUTES.

Proposed fix
-const routes = [
+const TEST_ROUTES = [
 ...
-    routes,
+    routes: TEST_ROUTES,
🤖 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/GuardrailChecksTab/index.test.tsx`
around lines 27 - 47, Rename the module-level immutable routes configuration
from routes to TEST_ROUTES, and update renderChecks to pass TEST_ROUTES to
renderRoute while preserving the existing route definitions.

Source: Coding guidelines

web/packages/studio/src/mocks/handlers/guardrails.ts (1)

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

Group external imports before internal imports.

  • web/packages/studio/src/mocks/handlers/guardrails.ts#L4-L10: Move the msw import into the external import group before @studio imports.
  • web/packages/studio/src/routes/guardrails/GuardrailChecksTab/index.tsx#L4-L12: Move the React type import into the external import group before @studio imports.
  • web/packages/studio/src/routes/guardrails/GuardrailChecksTab/index.test.tsx#L4-L15: Move the msw and react-router-dom imports into the external import group 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/mocks/handlers/guardrails.ts` around lines 4 - 10,
Reorder imports into external, internal, and relative groups: in
web/packages/studio/src/mocks/handlers/guardrails.ts (lines 4-10), place the msw
import before `@studio` imports; in
web/packages/studio/src/routes/guardrails/GuardrailChecksTab/index.tsx (lines
4-12), place the React type import before `@studio` imports; and in
web/packages/studio/src/routes/guardrails/GuardrailChecksTab/index.test.tsx
(lines 4-15), place msw and react-router-dom imports before `@studio` imports.
Preserve all imported symbols and behavior.

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/mocks/handlers/guardrails.ts`:
- Around line 102-115: Update the guardrail checks GET handler to read the
request’s parent filter and return only entries from mockGuardrailChecks whose
parent matches it, while preserving accurate pagination counts for the filtered
result. Add a route test covering cfg-2 and assert that it returns no checks.

---

Nitpick comments:
In `@web/packages/studio/src/mocks/handlers/guardrails.ts`:
- Around line 4-10: Reorder imports into external, internal, and relative
groups: in web/packages/studio/src/mocks/handlers/guardrails.ts (lines 4-10),
place the msw import before `@studio` imports; in
web/packages/studio/src/routes/guardrails/GuardrailChecksTab/index.tsx (lines
4-12), place the React type import before `@studio` imports; and in
web/packages/studio/src/routes/guardrails/GuardrailChecksTab/index.test.tsx
(lines 4-15), place msw and react-router-dom imports before `@studio` imports.
Preserve all imported symbols and behavior.

In `@web/packages/studio/src/routes/guardrails/GuardrailChecksTab/index.test.tsx`:
- Around line 27-47: Rename the module-level immutable routes configuration from
routes to TEST_ROUTES, and update renderChecks to pass TEST_ROUTES to
renderRoute while preserving the existing route definitions.
🪄 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: cd3923a0-66b8-44b6-a338-9737e9b7f569

📥 Commits

Reviewing files that changed from the base of the PR and between d962340 and 3e1b84b.

📒 Files selected for processing (3)
  • web/packages/studio/src/mocks/handlers/guardrails.ts
  • web/packages/studio/src/routes/guardrails/GuardrailChecksTab/index.test.tsx
  • web/packages/studio/src/routes/guardrails/GuardrailChecksTab/index.tsx

Comment thread web/packages/studio/src/mocks/handlers/guardrails.ts
@nakolean
nakolean added this pull request to the merge queue Jul 31, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 31, 2026
@nakolean
nakolean added this pull request to the merge queue Aug 3, 2026
Merged via the queue into main with commit 9e602f8 Aug 3, 2026
97 of 98 checks passed
@nakolean
nakolean deleted the astd-236-guardrail-check-details branch August 3, 2026 14: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