Skip to content

fix(output_parsers): parse trailing category tokens for safe verdicts in is_content_safe - #2207

Open
krishna11-dot wants to merge 1 commit into
NVIDIA-NeMo:developfrom
krishna11-dot:fix/is-content-safe-safe-violations
Open

fix(output_parsers): parse trailing category tokens for safe verdicts in is_content_safe#2207
krishna11-dot wants to merge 1 commit into
NVIDIA-NeMo:developfrom
krishna11-dot:fix/is-content-safe-safe-violations

Conversation

@krishna11-dot

Copy link
Copy Markdown

Summary

Fixes #2174

Problem

is_content_safe() in nemoguardrails/llm/output_parsers.py only extracted
trailing policy-category tokens (e.g., S1, S8) when the response prefix
was "unsafe". The "safe" branch unconditionally returned [True], silently
dropping any trailing category information.

Fix

  • Added _parse_safe_violations() helper that mirrors the existing
    _parse_unsafe_violations() logic
  • Updated the "safe" branch in is_content_safe() to call it
  • Re-enabled the previously commented-out assertion in
    test_content_safety_input_with_is_content_safe_parser_safe_with_violations

Testing

All 36 tests in tests/test_content_safety_integration.py pass.

@github-actions github-actions Bot added status: needs triage New issues that have not yet been reviewed or categorized. size: S needs: signing labels Jul 23, 2026
@krishna11-dot
krishna11-dot force-pushed the fix/is-content-safe-safe-violations branch from 686ec33 to 58aa1c3 Compare July 23, 2026 04:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: S status: needs triage New issues that have not yet been reviewed or categorized.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: is_content_safe() drops policy categories for "safe" verdicts with trailing category tokens

1 participant