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
5 changes: 3 additions & 2 deletions docs/user-guides/configuration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ nemoguardrails find-providers [--list]
```

The command supports two modes:

- Interactive mode (default): Guides you through selecting a provider type (text completion or chat completion) and then shows available providers for that type
- List mode (`--list`): Simply lists all available providers without interactive selection

Expand All @@ -126,7 +127,7 @@ models:
engine: deepseek
model: deepseek-reasoner
reasoning_config:
remove_thinking_traces: True
remove_reasoning_traces: True
start_token: "<think>"
end_token: "</think>"
```
Expand All @@ -136,7 +137,7 @@ By removing the traces, the guardrails runtime processes only the actual respons

You can specify the following parameters for a reasoning model:

- `remove_thinking_traces`: if the reasoning traces should be ignored (default `True`).
- `remove_reasoning_traces`: if the reasoning traces should be ignored (default `True`).
- `start_token`: the start token for the reasoning process (default `<think>`).
- `end_token`: the end token for the reasoning process (default `</think>`).

Expand Down
2 changes: 1 addition & 1 deletion examples/configs/llm/deepseek-r1/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ models:
engine: deepseek
model: deepseek-reasoner
reasoning_config:
remove_thinking_traces: True
remove_reasoning_traces: True
start_token: "<think>"
end_token: "</think>"
2 changes: 1 addition & 1 deletion nemoguardrails/llm/taskmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def should_remove_reasoning_traces_from_output(config, task):
model_config = (
model
and model.reasoning_config
and model.reasoning_config.remove_thinking_traces
and model.reasoning_config.remove_reasoning_traces
)

if config.rails.output.apply_to_reasoning_traces:
Expand Down
31 changes: 25 additions & 6 deletions nemoguardrails/rails/llm/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,13 @@
class ReasoningModelConfig(BaseModel):
"""Configuration for reasoning models/LLMs, including start and end tokens for reasoning traces."""

remove_thinking_traces: Optional[bool] = Field(
remove_reasoning_traces: Optional[bool] = Field(
default=True,
description="For reasoning models (e.g. DeepSeek-r1), if the output parser should remove thinking traces.",
description="For reasoning models (e.g. DeepSeek-r1), if the output parser should remove reasoning traces.",
)
remove_thinking_traces: Optional[bool] = Field(
default=None,
description="[DEPRECATED] Use remove_reasoning_traces instead. For reasoning models (e.g. DeepSeek-r1), if the output parser should remove thinking traces.",
)
start_token: Optional[str] = Field(
default="<think>",
Expand All @@ -84,6 +88,21 @@ class ReasoningModelConfig(BaseModel):
description="The end token used for reasoning traces.",
)

@model_validator(mode="after")
def handle_deprecated_field(self) -> "ReasoningModelConfig":
"""Handle the deprecated remove_thinking_traces field."""
if self.remove_thinking_traces is not None:
import warnings

warnings.warn(
"The 'remove_thinking_traces' field is deprecated and will be removed in 0.15.0 version. "
"Please use 'remove_reasoning_traces' instead.",
DeprecationWarning,
stacklevel=2,
)
self.remove_reasoning_traces = self.remove_thinking_traces
return self


class Model(BaseModel):
"""Configuration of a model used by the rails engine.
Expand Down Expand Up @@ -1250,23 +1269,23 @@ def check_reasoning_traces_with_dialog_rails(cls, values):
if hasattr(task_model, "reasoning_config")
else task_model.get("reasoning_config", {})
)
if not reasoning_config.get("remove_thinking_traces", True):
if not reasoning_config.get("remove_reasoning_traces", True):
violations.append(
f"Model '{task_model.get('type')}' has reasoning traces enabled in config.yml. "
f"Reasoning traces must be disabled for dialog rail tasks. "
f"Please update your config.yml to set 'remove_thinking_traces: true' under reasoning_config for this model."
f"Please update your config.yml to set 'remove_reasoning_traces: true' under reasoning_config for this model."
)
elif main_model:
reasoning_config = (
main_model.reasoning_config
if hasattr(main_model, "reasoning_config")
else main_model.get("reasoning_config", {})
)
if not reasoning_config.get("remove_thinking_traces", True):
if not reasoning_config.get("remove_reasoning_traces", True):
violations.append(
f"Main model has reasoning traces enabled in config.yml and is being used for dialog rail task '{task.value}'. "
f"Reasoning traces must be disabled when dialog rails are present. "
f"Please update your config.yml to set 'remove_thinking_traces: true' under reasoning_config for the main model."
f"Please update your config.yml to set 'remove_reasoning_traces: true' under reasoning_config for the main model."
)

if violations:
Expand Down
56 changes: 28 additions & 28 deletions tests/test_config_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def test_reasoning_traces_with_explicit_dialog_rails():
engine: openai
model: gpt-3.5-turbo-instruct
reasoning_config:
remove_thinking_traces: false
remove_reasoning_traces: false
rails:
dialog:
single_call:
Expand All @@ -150,7 +150,7 @@ def test_reasoning_traces_with_explicit_dialog_rails():
exc_info.value
)
assert (
"Please update your config.yml to set 'remove_thinking_traces: true' under reasoning_config"
"Please update your config.yml to set 'remove_reasoning_traces: true' under reasoning_config"
in str(exc_info.value)
)

Expand All @@ -165,7 +165,7 @@ def test_reasoning_traces_without_dialog_rails():
engine: openai
model: gpt-3.5-turbo-instruct
reasoning_config:
remove_thinking_traces: false
remove_reasoning_traces: false
""",
)

Expand Down Expand Up @@ -195,7 +195,7 @@ def test_input_rails_only_no_dialog_rails():
engine: openai
model: gpt-3.5-turbo-instruct
reasoning_config:
remove_thinking_traces: false
remove_reasoning_traces: false
rails:
input:
flows:
Expand All @@ -222,7 +222,7 @@ def test_no_dialog_tasks_with_only_output_rails():
engine: openai
model: gpt-3.5-turbo-instruct
reasoning_config:
remove_thinking_traces: false
remove_reasoning_traces: false
rails:
output:
flows:
Expand Down Expand Up @@ -250,7 +250,7 @@ def test_reasoning_traces_with_implicit_dialog_rails_user_bot_messages():
engine: openai
model: gpt-3.5-turbo-instruct
reasoning_config:
remove_thinking_traces: false
remove_reasoning_traces: false
""",
colang_content="""
define user express greeting
Expand All @@ -273,7 +273,7 @@ def test_reasoning_traces_with_implicit_dialog_rails_user_bot_messages():
exc_info.value
)
assert (
"Please update your config.yml to set 'remove_thinking_traces: true' under reasoning_config"
"Please update your config.yml to set 'remove_reasoning_traces: true' under reasoning_config"
in str(exc_info.value)
)

Expand All @@ -289,7 +289,7 @@ def test_reasoning_traces_with_implicit_dialog_rails_flows_only():
engine: openai
model: gpt-3.5-turbo-instruct
reasoning_config:
remove_thinking_traces: false
remove_reasoning_traces: False
""",
colang_content="""
define flow
Expand All @@ -309,7 +309,7 @@ def test_reasoning_traces_with_implicit_dialog_rails_flows_only():
exc_info.value
)
assert (
"Please update your config.yml to set 'remove_thinking_traces: true' under reasoning_config"
"Please update your config.yml to set 'remove_reasoning_traces: true' under reasoning_config"
in str(exc_info.value)
)

Expand All @@ -325,7 +325,7 @@ def test_reasoning_traces_with_implicit_dialog_rails_user_messages_only():
engine: openai
model: gpt-3.5-turbo-instruct
reasoning_config:
remove_thinking_traces: false
remove_reasoning_traces: false
""",
colang_content="""
define user express greeting
Expand All @@ -350,7 +350,7 @@ def test_reasoning_traces_with_bot_messages_only():
engine: openai
model: gpt-3.5-turbo-instruct
reasoning_config:
remove_thinking_traces: False
remove_reasoning_traces: False
""",
colang_content="""
define bot express greeting
Expand All @@ -377,12 +377,12 @@ def test_reasoning_traces_with_dedicated_task_models():
engine: openai
model: gpt-3.5-turbo-instruct
reasoning_config:
remove_thinking_traces: false
remove_reasoning_traces: false
- type: generate_user_intent
engine: openai
model: gpt-3.5-turbo-instruct
reasoning_config:
remove_thinking_traces: false
remove_reasoning_traces: false
rails:
dialog:
single_call:
Expand All @@ -398,7 +398,7 @@ def test_reasoning_traces_with_dedicated_task_models():
exc_info.value
)
assert (
"Please update your config.yml to set 'remove_thinking_traces: true' under reasoning_config"
"Please update your config.yml to set 'remove_reasoning_traces: true' under reasoning_config"
in str(exc_info.value)
)

Expand All @@ -414,15 +414,15 @@ def test_reasoning_traces_with_mixed_task_models():
engine: openai
model: gpt-3.5-turbo-instruct
reasoning_config:
remove_thinking_traces: false
remove_reasoning_traces: false
- type: generate_bot_message
engine: openai
model: gpt-3.5-turbo-instruct
- type: generate_user_intent
engine: openai
model: gpt-3.5-turbo-instruct
reasoning_config:
remove_thinking_traces: false
remove_reasoning_traces: false
rails:
dialog:
single_call:
Expand All @@ -438,7 +438,7 @@ def test_reasoning_traces_with_mixed_task_models():
exc_info.value
)
assert (
"Please update your config.yml to set 'remove_thinking_traces: true' under reasoning_config"
"Please update your config.yml to set 'remove_reasoning_traces: true' under reasoning_config"
in str(exc_info.value)
)

Expand All @@ -457,15 +457,15 @@ def test_reasoning_traces_with_all_dialog_tasks():
engine: openai
model: gpt-3.5-turbo-instruct
reasoning_config:
remove_thinking_traces: false
remove_reasoning_traces: false
- type: generate_user_intent
engine: openai
model: gpt-3.5-turbo-instruct
- type: generate_next_steps
engine: openai
model: gpt-3.5-turbo-instruct
reasoning_config:
remove_thinking_traces: false
remove_reasoning_traces: false
- type: generate_intent_steps_message
engine: openai
model: gpt-3.5-turbo-instruct
Expand All @@ -487,7 +487,7 @@ def test_reasoning_traces_with_all_dialog_tasks():
)
assert "Reasoning traces must be disabled for dialog rail tasks" in error_message
assert (
"Please update your config.yml to set 'remove_thinking_traces: true' under reasoning_config"
"Please update your config.yml to set 'remove_reasoning_traces: true' under reasoning_config"
in error_message
)

Expand All @@ -505,12 +505,12 @@ def test_reasoning_traces_with_dedicated_models_no_dialog_rails():
engine: openai
model: gpt-3.5-turbo-instruct
reasoning_config:
remove_thinking_traces: false
remove_reasoning_traces: false
- type: generate_user_intent
engine: openai
model: gpt-3.5-turbo-instruct
reasoning_config:
remove_thinking_traces: false
remove_reasoning_traces: false
""",
)

Expand All @@ -529,7 +529,7 @@ def test_reasoning_traces_with_implicit_dialog_rails_and_dedicated_models():
engine: openai
model: gpt-3.5-turbo-instruct
reasoning_config:
remove_thinking_traces: false
remove_reasoning_traces: false
""",
colang_content="""
define user express greeting
Expand All @@ -553,7 +553,7 @@ def test_reasoning_traces_with_implicit_dialog_rails_and_dedicated_models():
exc_info.value
)
assert (
"Please update your config.yml to set 'remove_thinking_traces: true' under reasoning_config"
"Please update your config.yml to set 'remove_reasoning_traces: true' under reasoning_config"
in str(exc_info.value)
)

Expand All @@ -569,7 +569,7 @@ def test_reasoning_traces_with_partial_dedicated_models():
engine: openai
model: gpt-3.5-turbo-instruct
reasoning_config:
remove_thinking_traces: false
remove_reasoning_traces: false
- type: generate_bot_message
engine: openai
model: gpt-3.5-turbo-instruct
Expand All @@ -587,7 +587,7 @@ def test_reasoning_traces_with_partial_dedicated_models():
exc_info.value
)
assert (
"Please update your config.yml to set 'remove_thinking_traces: true' under reasoning_config"
"Please update your config.yml to set 'remove_reasoning_traces: true' under reasoning_config"
in str(exc_info.value)
)

Expand All @@ -602,7 +602,7 @@ def test_reasoning_traces_with_implicit_dialog_rails_embeddings_only():
engine: openai
model: gpt-3.5-turbo-instruct
reasoning_config:
remove_thinking_traces: False
remove_reasoning_traces: False
rails:
dialog:
user_messages:
Expand All @@ -626,7 +626,7 @@ def test_reasoning_traces_with_bot_messages_embeddings_only():
engine: openai
model: gpt-3.5-turbo-instruct
reasoning_config:
remove_thinking_traces: False
remove_reasoning_traces: False
rails:
dialog:
user_messages:
Expand Down
Loading