Skip to content

nemoguard_parse_prompt_safety and nemoguard_parse_response_safety silently drop violation categories due to wrong JSON key #2010

Description

@nac7

Bug

nemoguard_parse_prompt_safety and nemoguard_parse_response_safety in nemoguardrails/llm/output_parsers.py look for key \"Safety Categories\" when extracting violation categories from the NemoGuard model response, but the NemoGuard ContentSafety model actually returns key \"Violated Categories\" (as documented in each function's own docstring).

Impact

Every unsafe response from the NemoGuard model silently loses its violation categories. Callers receive [False] with an empty category list instead of [False, \"violence\", \"hate\"] (or whichever categories were flagged). This affects:

  • Audit logging that records which policy categories were violated
  • Downstream guardrail logic that acts differently based on violation type
  • Compliance reporting

Reproduction

from nemoguardrails.llm.output_parsers import nemoguard_parse_prompt_safety

# NemoGuard model output (format documented in the function's own docstring)
response = '{"User Safety": "unsafe", "Violated Categories": "violence, hate_speech"}'

result = nemoguard_parse_prompt_safety(response)
print(result)
# Got:    [False]          ← categories silently dropped
# Expect: [False, 'violence', 'hate_speech']

Root Cause

nemoguardrails/llm/output_parsers.py lines 163 and 202:

# Both functions check for wrong key "Safety Categories"
if "Safety Categories" in parsed_json_result:
    safety_categories = [...]
else:
    safety_categories = []   # ← always falls here

The NemoGuard model returns "Violated Categories" (documented in the same functions' docstrings), not "Safety Categories".

Fix

Change "Safety Categories""Violated Categories" on lines 163 and 202 of output_parsers.py.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions