Skip to content

fix(guardrails): Ensure input rail logs are not dropped from final response - #827

Merged
JashG merged 2 commits into
mainfrom
jgulabrai/preserve-input-logs
Jul 22, 2026
Merged

fix(guardrails): Ensure input rail logs are not dropped from final response#827
JashG merged 2 commits into
mainfrom
jgulabrai/preserve-input-logs

Conversation

@JashG

@JashG JashG commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Stash the input-rail GenerationResponse in plugin state before returning an ImmediateResponse, so response middleware can still rebuild guardrails_data.log correctly.

IGW still runs response middleware after an input is blocked, which is where the guardrails_data field gets populated from the input and output rail results. Without this change, the blocked input's logs would be silently not included in the response.

Summary by CodeRabbit

  • Bug Fixes
    • Preserved input-rail details when a request is blocked.
    • Ensured requested guardrails logging remains available in blocked responses.
    • Improved response metadata to include the relevant input and output rail results.

@JashG
JashG requested review from a team as code owners July 21, 2026 19:22
@github-actions github-actions Bot added the fix label Jul 21, 2026
@JashG
JashG requested a review from gabwow July 21, 2026 19:24
@coderabbitai

coderabbitai Bot commented Jul 21, 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: 459c97fe-bdb8-4c4b-8003-f167625342e6

📥 Commits

Reviewing files that changed from the base of the PR and between e3f1407 and ba903ee.

📒 Files selected for processing (2)
  • plugins/nemo-guardrails/src/nemo_guardrails_plugin/middleware.py
  • plugins/nemo-guardrails/tests/unit/test_middleware.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • plugins/nemo-guardrails/src/nemo_guardrails_plugin/middleware.py
  • plugins/nemo-guardrails/tests/unit/test_middleware.py

📝 Walkthrough

Walkthrough

process_request now stores the input-rails result before blocked requests return. Tests verify that process_response preserves requested input and output rail log fields.

Changes

Blocked input-rail state

Layer / File(s) Summary
Persist input-rail results and validate response logs
plugins/nemo-guardrails/src/nemo_guardrails_plugin/middleware.py, plugins/nemo-guardrails/tests/unit/test_middleware.py
The input-rails GenerationResponse is stored before blocked responses return. Tests verify state persistence and guardrails_data.log.activated_rails values for blocked input and successful output rails.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 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 fix: preserving input rail logs in the final response.
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/preserve-input-logs

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

@github-actions

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor
Suite Lines Covered Line Rate Branch Rate
Unit Tests 27114/34832 77.8% 62.1%
Integration Tests 15891/33443 47.5% 19.9%

Comment thread plugins/nemo-guardrails/tests/unit/test_middleware.py
@gabwow
gabwow self-requested a review July 21, 2026 20:00
JashG added 2 commits July 22, 2026 11:36
…sponse

Signed-off-by: Jash Gulabrai <jgulabrai@nvidia.com>
Signed-off-by: Jash Gulabrai <jgulabrai@nvidia.com>
@JashG
JashG force-pushed the jgulabrai/preserve-input-logs branch from e3f1407 to ba903ee Compare July 22, 2026 15:37
@JashG
JashG added this pull request to the merge queue Jul 22, 2026
Merged via the queue into main with commit 517ac85 Jul 22, 2026
61 checks passed
@JashG
JashG deleted the jgulabrai/preserve-input-logs branch July 22, 2026 16:45
soluwalana pushed a commit that referenced this pull request Jul 22, 2026
…sponse (#827)

* fix(guardrails): Ensure input rail logs are not dropped from final response

Signed-off-by: Jash Gulabrai <jgulabrai@nvidia.com>

* Address MR comment

Signed-off-by: Jash Gulabrai <jgulabrai@nvidia.com>

---------

Signed-off-by: Jash Gulabrai <jgulabrai@nvidia.com>
Signed-off-by: Sam Oluwalana <soluwalana@nvidia.com>
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