Skip to content

Conversation

@Pouyanpi
Copy link
Collaborator

When generate_async is called with options={"dialog": False, "output": True} and no bot_message is provided in context, output rails were incorrectly running and checking None. This fix ensures output rails only run when there's actual output to check.

Test matrix:

input output dialog expect_input expect_output
T T T T T
T T F T F ← bug fix
T F T T F
T F F T F
F T T F T
F T F F F ← bug fix
F F T F F
F F F F F

…age provided

When `generate_async` is called with `options={"dialog": False,
"output": True}` and no `bot_message` is provided in context, output
rails were incorrectly running and checking `None`. This fix ensures
output rails only run when there's actual output to check.
@Pouyanpi Pouyanpi added this to the 0.20.0 milestone Nov 27, 2025
@Pouyanpi Pouyanpi self-assigned this Nov 27, 2025
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Nov 27, 2025

Greptile Overview

Greptile Summary

Fixed a bug where output rails were incorrectly attempting to validate None when dialog=False and no bot_message was provided in the context. The fix adds a check for $bot_message is None to skip output rails in this scenario.

  • Modified run dialog rails flow in llm_flows.co:32 to check both output == False OR $bot_message is None before skipping output rails
  • Added comprehensive parametrized test with 8 combinations of input/output/dialog options to validate the fix
  • The test matrix confirms output rails now correctly skip when dialog=False and there's no bot message to check

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The fix is surgical and well-tested: it adds a single null check to prevent output rails from running on None values, which addresses the exact bug described. The comprehensive parametrized test validates all 8 combinations of rail options, ensuring no regression in existing behavior while fixing the reported issue.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
nemoguardrails/rails/llm/llm_flows.co 5/5 Fixed output rails logic to check for None $bot_message when dialog is disabled, preventing null checks
tests/test_generation_options.py 5/5 Added comprehensive parametrized test covering all 8 combinations of input/output/dialog rail options

Sequence Diagram

sequenceDiagram
    participant User
    participant generate_async
    participant run_dialog_rails
    participant process_bot_message
    participant output_rails

    User->>generate_async: "Hello!" with options{dialog: False, output: True}
    Note over generate_async: No bot_message in context<br/>($bot_message is None)
    generate_async->>run_dialog_rails: Process with generation_options
    
    alt dialog == False AND (output == False OR $bot_message is None)
        Note over run_dialog_rails: NEW: Check added for $bot_message is None
        run_dialog_rails->>User: Skip output rails<br/>Return StartUtteranceBotAction($user_message)
    else dialog == False AND output == True AND $bot_message exists
        run_dialog_rails->>process_bot_message: Create BotMessage($bot_message)
        process_bot_message->>output_rails: Run output rails on $bot_message
        output_rails->>User: Return processed message
    else dialog == True
        Note over run_dialog_rails: Normal flow: generate intent & bot message
        run_dialog_rails->>process_bot_message: Continue usual process
        process_bot_message->>output_rails: Run output rails
        output_rails->>User: Return processed message
    end
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@Pouyanpi Pouyanpi added the bug Something isn't working label Nov 27, 2025
@codecov
Copy link

codecov bot commented Nov 27, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants