Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions nemoguardrails/rails/llm/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1199,11 +1199,10 @@ def check_reasoning_traces_with_dialog_rails(cls, values):
]

# dialog rails are activated (explicitly or implicitly)
has_dialog_rails = (
bool(dialog_rails)
or bool(values.get("user_messages"))
or bool(values.get("bot_messages"))
or bool(values.get("flows"))
has_dialog_rails = bool(dialog_rails) or (
bool(values.get("user_messages"))
and bool(values.get("bot_messages"))
# and bool(values.get("flows"))
)

if has_dialog_rails:
Expand Down
82 changes: 31 additions & 51 deletions tests/test_config_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ def test_reasoning_traces_with_implicit_dialog_rails_flows_only():
define flow
user express greeting
bot express greeting
define user express greeting
"hi"
define bot express greeting
"HI HI"
""",
)

Expand All @@ -311,65 +315,41 @@ def test_reasoning_traces_with_implicit_dialog_rails_flows_only():


def test_reasoning_traces_with_implicit_dialog_rails_user_messages_only():
"""Test that reasoning traces cannot be enabled when dialog rails are implicitly enabled thru user messages only."""
"""Test that reasoning traces cannot be enabled when dialog rails are implicitly enabled through user messages (user canonical forms) only."""

with pytest.raises(ValueError) as exc_info:
_ = RailsConfig.from_content(
yaml_content="""
models:
- type: main
engine: openai
model: gpt-3.5-turbo-instruct
reasoning_config:
remove_thinking_traces: false
""",
colang_content="""
_ = RailsConfig.from_content(
yaml_content="""
models:
- type: main
engine: openai
model: gpt-3.5-turbo-instruct
reasoning_config:
remove_thinking_traces: false
""",
colang_content="""
define user express greeting
"hello"
"hi"
""",
)

assert "Main model has reasoning traces enabled in config.yml" in str(
exc_info.value
)
assert "Reasoning traces must be disabled when dialog rails are present" in str(
exc_info.value
)
assert (
"Please update your config.yml to set 'remove_thinking_traces: true' under reasoning_config"
in str(exc_info.value)
""",
)


def test_reasoning_traces_with_implicit_dialog_rails_bot_messages_only():
"""Test that reasoning traces cannot be enabled when dialog rails are implicitly enabled thru bot messages only."""
def test_reasoning_traces_with_bot_messages_only():
"""Test that reasoning traces can exist with bot messages only."""

with pytest.raises(ValueError) as exc_info:
_ = RailsConfig.from_content(
yaml_content="""
models:
- type: main
engine: openai
model: gpt-3.5-turbo-instruct
reasoning_config:
remove_thinking_traces: false
""",
colang_content="""
define bot express greeting
"Hello there!"
""",
)

assert "Main model has reasoning traces enabled in config.yml" in str(
exc_info.value
)
assert "Reasoning traces must be disabled when dialog rails are present" in str(
exc_info.value
)
assert (
"Please update your config.yml to set 'remove_thinking_traces: true' under reasoning_config"
in str(exc_info.value)
_ = RailsConfig.from_content(
yaml_content="""
models:
- type: main
engine: openai
model: gpt-3.5-turbo-instruct
reasoning_config:
remove_thinking_traces: False
""",
colang_content="""
define bot express greeting
"Hello there!"
""",
)


Expand Down