Skip to content

test(guardrails): Add e2e tests for config caching and various rail types#740

Open
JashG wants to merge 5 commits into
mainfrom
jgulabrai/guardrails-e2e-tests-3
Open

test(guardrails): Add e2e tests for config caching and various rail types#740
JashG wants to merge 5 commits into
mainfrom
jgulabrai/guardrails-e2e-tests-3

Conversation

@JashG

@JashG JashG commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

…ypes

Summary by CodeRabbit

  • New Features
    • Expanded Guardrails E2E smoke coverage for additional rail types (topic control, self-checks, injection detection, multimodal safety, reasoning-based safety) and parallel input veto behavior.
    • Added E2E validation for real background Guardrails config cache refresh, including both updates and deletions.
  • Tests
    • Added a new config cache refresh E2E module and reworked non-streaming chat-completions test request helpers/assertions.
    • Introduced an autouse probe-model setup to prevent early requests from bypassing guardrails.
  • Bug Fixes
    • Ensured input-rails results are consistently available for activated-rails logging even when an immediate refusal is returned.
  • Refactor
    • Improved Guardrails E2E utilities for readiness, config setup, and cleanup; added response inspection helpers.

…ypes

Signed-off-by: Jash Gulabrai <jgulabrai@nvidia.com>
@JashG
JashG requested review from a team as code owners July 16, 2026 21:00
@github-actions github-actions Bot added the test conventional-commit type label Jul 16, 2026
@coderabbitai

coderabbitai Bot commented Jul 16, 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: 033c3814-cafa-42a4-a750-bb268896f05e

📥 Commits

Reviewing files that changed from the base of the PR and between 95e923c and a82aa1f.

📒 Files selected for processing (2)
  • e2e/guardrails/conftest.py
  • e2e/guardrails/utils.py

📝 Walkthrough

Walkthrough

Guardrails E2E utilities now use explicit request parameters and lifecycle helpers. New tests cover multiple rail types and real background refresh behavior. Middleware state is populated before blocked responses, and existing non-streaming tests use a centralized request helper.

Changes

Guardrails E2E validation

Layer / File(s) Summary
Input rail response state handling
plugins/nemo-guardrails/src/nemo_guardrails_plugin/middleware.py
Stores input-rail generation results before blocked immediate responses and removes the later duplicate state update.
Guardrails request and lifecycle utilities
e2e/guardrails/utils.py
Adds response inspection, explicit chat request construction, guarded-model readiness, probe provisioning, configuration setup, and cleanup helpers.
Probe model initialization
e2e/guardrails/conftest.py
Provisions the probe model through an autouse module-scoped fixture before Guardrails tests run.
Chat completion request migration
e2e/guardrails/test_chat_completions.py
Routes non-streaming tests through _post while preserving metadata and validation assertions.
Guardrails rail-type smoke coverage
e2e/guardrails/test_rail_types.py
Adds E2E coverage for topic control, self-check, injection detection, multimodal vision, content-safety reasoning, and parallel input rails.
Guardrails configuration cache refresh
e2e/guardrails/test_config_cache_refresh.py
Verifies configuration updates and deletions after real background refresh behavior.

Sequence Diagram(s)

sequenceDiagram
  participant Test
  participant NeMoPlatform
  participant Gateway
  participant GuardrailsMiddleware
  participant GuardrailConfig
  participant Backend
  Test->>NeMoPlatform: configure guarded VirtualModel
  Test->>Gateway: submit chat completion
  Gateway->>GuardrailConfig: load Guardrails configuration
  Gateway->>GuardrailsMiddleware: run input rails
  GuardrailsMiddleware->>GuardrailsMiddleware: store input generation response
  Gateway->>Backend: request model response
  Backend-->>Gateway: return response
  Gateway-->>Test: return allowed or blocked result
  Test->>NeMoPlatform: update or delete GuardrailConfig
  Gateway->>GuardrailConfig: refresh configuration
  Gateway-->>Test: reflect updated blocking or fail-closed state
Loading

Possibly related PRs

Suggested labels: fix

Suggested reviewers: albcui, gabwow

🚥 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 Title matches the main change: new e2e tests for guardrails config caching and multiple rail types.
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 jgulabrai/guardrails-e2e-tests-3

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)
e2e/guardrails/utils.py (1)

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

Duplicate blocked/activated-rails logic across files. utils.py now exports is_chat_response_blocked/activated_rails_by_name, already adopted by test_rail_types.py and test_config_cache_refresh.py, but test_chat_completions.py still keeps its own copies.

  • e2e/guardrails/utils.py#L239-L252: canonical implementation — no change needed here.
  • e2e/guardrails/test_chat_completions.py#L50-L52: replace _assert_blocked's finish_reason check with is_chat_response_blocked(response).
  • e2e/guardrails/test_chat_completions.py#L67-L71: drop _activated_rails_by_name and import activated_rails_by_name from utils.py.
♻️ Proposed consolidation
-def _assert_blocked(response: dict[str, Any]) -> None:
-    assert response["choices"][0]["finish_reason"] == "content_filter"
+def _assert_blocked(response: dict[str, Any]) -> None:
+    assert is_chat_response_blocked(response)
     assert response["choices"][0]["message"]["content"] == REFUSAL_TEXT
-def _activated_rails_by_name(response: dict[str, Any]) -> dict[str, dict[str, Any]]:
-    guardrails_data = response.get("guardrails_data") or {}
-    log = guardrails_data.get("log") or {}
-    activated_rails = log.get("activated_rails") or []
-    return {rail["name"]: rail for rail in activated_rails}
+# use `activated_rails_by_name` imported from utils.py
🤖 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 `@e2e/guardrails/utils.py` around lines 239 - 252, The canonical
implementations in e2e/guardrails/utils.py lines 239-252 require no direct
change. In e2e/guardrails/test_chat_completions.py lines 50-52, update
_assert_blocked to call is_chat_response_blocked(response) instead of checking
finish_reason directly. In e2e/guardrails/test_chat_completions.py lines 67-71,
remove _activated_rails_by_name and import and use activated_rails_by_name from
utils.py.
🤖 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 `@e2e/guardrails/utils.py`:
- Around line 239-252: The canonical implementations in e2e/guardrails/utils.py
lines 239-252 require no direct change. In
e2e/guardrails/test_chat_completions.py lines 50-52, update _assert_blocked to
call is_chat_response_blocked(response) instead of checking finish_reason
directly. In e2e/guardrails/test_chat_completions.py lines 67-71, remove
_activated_rails_by_name and import and use activated_rails_by_name from
utils.py.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 937014f6-913e-4daf-a00f-cb579082fcab

📥 Commits

Reviewing files that changed from the base of the PR and between 267d246 and 8f6b51c.

📒 Files selected for processing (4)
  • e2e/guardrails/test_chat_completions.py
  • e2e/guardrails/test_config_cache_refresh.py
  • e2e/guardrails/test_rail_types.py
  • e2e/guardrails/utils.py

Signed-off-by: Jash Gulabrai <jgulabrai@nvidia.com>
@JashG
JashG requested a review from albcui July 16, 2026 21:13
@github-actions

github-actions Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor
Suite Lines Covered Line Rate Branch Rate
Unit Tests 25701/32944 78.0% 62.7%
Integration Tests 14784/31593 46.8% 19.2%

JashG added 3 commits July 17, 2026 10:46
Signed-off-by: Jash Gulabrai <jgulabrai@nvidia.com>
Signed-off-by: Jash Gulabrai <jgulabrai@nvidia.com>
Signed-off-by: Jash Gulabrai <jgulabrai@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test conventional-commit type

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant