Skip to content

fix(guardrails): Surface 500 when guardrail result cannot be parsed - #1213

Open
JashG wants to merge 1 commit into
mainfrom
fix/guardrails-missing-activation-log
Open

fix(guardrails): Surface 500 when guardrail result cannot be parsed#1213
JashG wants to merge 1 commit into
mainfrom
fix/guardrails-missing-activation-log

Conversation

@JashG

@JashG JashG commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Addresses edge case where a rail result cannot be parsed from the underlying GenerationResponse. Previously, we blocked the request and DEBUG logged the error. This PR updates the plugin to return an explicit 500 with a WARNING log.

Changes

  • responses.py: Refactored is_blocked_generation_response to accept GenerationLog directly instead of GenerationResponse. The caller (i.e. the plugin middleware) returns early if there is no GenerationLog.
  • middleware.py: Added a log is None guard in both process_request (input rails) and process_response (output rails) that raises InferenceMiddlewareError(status_code=500) and logs at WARNING before the blocked/unblocked branch is evaluated.
  • Updated tests

Type of Change

  • Code change (feature, bug fix, or refactor)
  • Code change with documentation updates
  • Documentation only
  • Contributor tooling or automation
  • CI, build, or test infrastructure

Quality Gates

  • Tests added or updated for changed behavior
  • Existing tests cover changed behavior — justification:
  • Tests not applicable — justification:
  • Documentation updated for user-visible behavior
  • Documentation not applicable — justification:

Verification

  • Pull request title follows the repository's Conventional Commit format
  • Every commit includes an appropriate Signed-off-by: trailer
  • uv run pre-commit run -a passes, or any blocked checks are identified below
  • Targeted tests pass, or tests are marked not applicable above
  • No secrets, API keys, or credentials are included

Targeted validation:

uv run --frozen pytest plugins/nemo-guardrails/ -x -q
412 passed, 292 warnings

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of missing generation logs during input and output guardrail processing.
    • Requests now return a clear HTTP 500 error when guardrail results cannot be determined.
    • Blocked responses are detected more reliably based on activated rail results.
  • Tests

    • Added coverage for missing logs and blocked, allowed, empty, and non-stopping rail outcomes.

Signed-off-by: Jash Gulabrai <jgulabrai@nvidia.com>
@JashG
JashG requested review from a team as code owners August 10, 2026 19:38
@github-actions github-actions Bot added the fix label Aug 10, 2026
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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: 77e151a1-24ec-405c-af0d-e0bf51e965b3

📥 Commits

Reviewing files that changed from the base of the PR and between 378ca94 and 46ba18e.

📒 Files selected for processing (4)
  • plugins/nemo-guardrails/src/nemo_guardrails_plugin/middleware.py
  • plugins/nemo-guardrails/src/nemo_guardrails_plugin/responses.py
  • plugins/nemo-guardrails/tests/unit/test_middleware.py
  • plugins/nemo-guardrails/tests/unit/test_responses.py

📝 Walkthrough

Walkthrough

Guardrail middleware now rejects generation responses without activation logs with HTTP 500 errors. Block detection accepts GenerationLog directly and checks activated rails. Unit tests cover input, output, and blocked-generation cases.

Changes

Guardrail log handling

Layer / File(s) Summary
Blocked response detection
plugins/nemo-guardrails/src/nemo_guardrails_plugin/responses.py, plugins/nemo-guardrails/tests/unit/test_responses.py
is_blocked_generation_response now accepts GenerationLog and checks stopped activated rails. Tests cover stopped, non-stopped, empty, and explicitly non-blocking rails.
Middleware log validation
plugins/nemo-guardrails/src/nemo_guardrails_plugin/middleware.py, plugins/nemo-guardrails/tests/unit/test_middleware.py
Input and output rail processing return a 500 InferenceMiddlewareError when GenerationResponse.log is missing. Tests validate both paths.

Suggested reviewers: a2bondar

🚥 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 summarizes the main change: returning HTTP 500 when the guardrail result cannot be parsed.
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 fix/guardrails-missing-activation-log

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

@JashG
JashG requested a review from gabwow August 10, 2026 19:49
@github-actions

github-actions Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor
Suite Lines Covered Line Rate Branch Rate
Unit Tests 32003/40616 78.8% 63.6%
Integration Tests 18553/38542 48.1% 20.8%

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.

1 participant