Skip to content

Commit f1dfbd6

Browse files
authored
refactor(config): rename remove_thinking_traces field to remove_reasoning_traces (#1176)
1 parent 457cd48 commit f1dfbd6

File tree

7 files changed

+111
-55
lines changed

7 files changed

+111
-55
lines changed

docs/user-guides/configuration-guide.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ nemoguardrails find-providers [--list]
103103
```
104104

105105
The command supports two modes:
106+
106107
- Interactive mode (default): Guides you through selecting a provider type (text completion or chat completion) and then shows available providers for that type
107108
- List mode (`--list`): Simply lists all available providers without interactive selection
108109

@@ -126,7 +127,7 @@ models:
126127
engine: deepseek
127128
model: deepseek-reasoner
128129
reasoning_config:
129-
remove_thinking_traces: True
130+
remove_reasoning_traces: True
130131
start_token: "<think>"
131132
end_token: "</think>"
132133
```
@@ -136,7 +137,7 @@ By removing the traces, the guardrails runtime processes only the actual respons
136137

137138
You can specify the following parameters for a reasoning model:
138139

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

examples/configs/llm/deepseek-r1/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ models:
33
engine: deepseek
44
model: deepseek-reasoner
55
reasoning_config:
6-
remove_thinking_traces: True
6+
remove_reasoning_traces: True
77
start_token: "<think>"
88
end_token: "</think>"

nemoguardrails/llm/taskmanager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def should_remove_reasoning_traces_from_output(config, task):
8383
model_config = (
8484
model
8585
and model.reasoning_config
86-
and model.reasoning_config.remove_thinking_traces
86+
and model.reasoning_config.remove_reasoning_traces
8787
)
8888

8989
if config.rails.output.apply_to_reasoning_traces:

nemoguardrails/rails/llm/config.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,13 @@
7171
class ReasoningModelConfig(BaseModel):
7272
"""Configuration for reasoning models/LLMs, including start and end tokens for reasoning traces."""
7373

74-
remove_thinking_traces: Optional[bool] = Field(
74+
remove_reasoning_traces: Optional[bool] = Field(
7575
default=True,
76-
description="For reasoning models (e.g. DeepSeek-r1), if the output parser should remove thinking traces.",
76+
description="For reasoning models (e.g. DeepSeek-r1), if the output parser should remove reasoning traces.",
77+
)
78+
remove_thinking_traces: Optional[bool] = Field(
79+
default=None,
80+
description="[DEPRECATED] Use remove_reasoning_traces instead. For reasoning models (e.g. DeepSeek-r1), if the output parser should remove thinking traces.",
7781
)
7882
start_token: Optional[str] = Field(
7983
default="<think>",
@@ -84,6 +88,21 @@ class ReasoningModelConfig(BaseModel):
8488
description="The end token used for reasoning traces.",
8589
)
8690

91+
@model_validator(mode="after")
92+
def handle_deprecated_field(self) -> "ReasoningModelConfig":
93+
"""Handle the deprecated remove_thinking_traces field."""
94+
if self.remove_thinking_traces is not None:
95+
import warnings
96+
97+
warnings.warn(
98+
"The 'remove_thinking_traces' field is deprecated and will be removed in 0.15.0 version. "
99+
"Please use 'remove_reasoning_traces' instead.",
100+
DeprecationWarning,
101+
stacklevel=2,
102+
)
103+
self.remove_reasoning_traces = self.remove_thinking_traces
104+
return self
105+
87106

88107
class Model(BaseModel):
89108
"""Configuration of a model used by the rails engine.
@@ -1250,23 +1269,23 @@ def check_reasoning_traces_with_dialog_rails(cls, values):
12501269
if hasattr(task_model, "reasoning_config")
12511270
else task_model.get("reasoning_config", {})
12521271
)
1253-
if not reasoning_config.get("remove_thinking_traces", True):
1272+
if not reasoning_config.get("remove_reasoning_traces", True):
12541273
violations.append(
12551274
f"Model '{task_model.get('type')}' has reasoning traces enabled in config.yml. "
12561275
f"Reasoning traces must be disabled for dialog rail tasks. "
1257-
f"Please update your config.yml to set 'remove_thinking_traces: true' under reasoning_config for this model."
1276+
f"Please update your config.yml to set 'remove_reasoning_traces: true' under reasoning_config for this model."
12581277
)
12591278
elif main_model:
12601279
reasoning_config = (
12611280
main_model.reasoning_config
12621281
if hasattr(main_model, "reasoning_config")
12631282
else main_model.get("reasoning_config", {})
12641283
)
1265-
if not reasoning_config.get("remove_thinking_traces", True):
1284+
if not reasoning_config.get("remove_reasoning_traces", True):
12661285
violations.append(
12671286
f"Main model has reasoning traces enabled in config.yml and is being used for dialog rail task '{task.value}'. "
12681287
f"Reasoning traces must be disabled when dialog rails are present. "
1269-
f"Please update your config.yml to set 'remove_thinking_traces: true' under reasoning_config for the main model."
1288+
f"Please update your config.yml to set 'remove_reasoning_traces: true' under reasoning_config for the main model."
12701289
)
12711290

12721291
if violations:

tests/test_config_validation.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def test_reasoning_traces_with_explicit_dialog_rails():
135135
engine: openai
136136
model: gpt-3.5-turbo-instruct
137137
reasoning_config:
138-
remove_thinking_traces: false
138+
remove_reasoning_traces: false
139139
rails:
140140
dialog:
141141
single_call:
@@ -150,7 +150,7 @@ def test_reasoning_traces_with_explicit_dialog_rails():
150150
exc_info.value
151151
)
152152
assert (
153-
"Please update your config.yml to set 'remove_thinking_traces: true' under reasoning_config"
153+
"Please update your config.yml to set 'remove_reasoning_traces: true' under reasoning_config"
154154
in str(exc_info.value)
155155
)
156156

@@ -165,7 +165,7 @@ def test_reasoning_traces_without_dialog_rails():
165165
engine: openai
166166
model: gpt-3.5-turbo-instruct
167167
reasoning_config:
168-
remove_thinking_traces: false
168+
remove_reasoning_traces: false
169169
""",
170170
)
171171

@@ -195,7 +195,7 @@ def test_input_rails_only_no_dialog_rails():
195195
engine: openai
196196
model: gpt-3.5-turbo-instruct
197197
reasoning_config:
198-
remove_thinking_traces: false
198+
remove_reasoning_traces: false
199199
rails:
200200
input:
201201
flows:
@@ -222,7 +222,7 @@ def test_no_dialog_tasks_with_only_output_rails():
222222
engine: openai
223223
model: gpt-3.5-turbo-instruct
224224
reasoning_config:
225-
remove_thinking_traces: false
225+
remove_reasoning_traces: false
226226
rails:
227227
output:
228228
flows:
@@ -250,7 +250,7 @@ def test_reasoning_traces_with_implicit_dialog_rails_user_bot_messages():
250250
engine: openai
251251
model: gpt-3.5-turbo-instruct
252252
reasoning_config:
253-
remove_thinking_traces: false
253+
remove_reasoning_traces: false
254254
""",
255255
colang_content="""
256256
define user express greeting
@@ -273,7 +273,7 @@ def test_reasoning_traces_with_implicit_dialog_rails_user_bot_messages():
273273
exc_info.value
274274
)
275275
assert (
276-
"Please update your config.yml to set 'remove_thinking_traces: true' under reasoning_config"
276+
"Please update your config.yml to set 'remove_reasoning_traces: true' under reasoning_config"
277277
in str(exc_info.value)
278278
)
279279

@@ -289,7 +289,7 @@ def test_reasoning_traces_with_implicit_dialog_rails_flows_only():
289289
engine: openai
290290
model: gpt-3.5-turbo-instruct
291291
reasoning_config:
292-
remove_thinking_traces: false
292+
remove_reasoning_traces: False
293293
""",
294294
colang_content="""
295295
define flow
@@ -309,7 +309,7 @@ def test_reasoning_traces_with_implicit_dialog_rails_flows_only():
309309
exc_info.value
310310
)
311311
assert (
312-
"Please update your config.yml to set 'remove_thinking_traces: true' under reasoning_config"
312+
"Please update your config.yml to set 'remove_reasoning_traces: true' under reasoning_config"
313313
in str(exc_info.value)
314314
)
315315

@@ -325,7 +325,7 @@ def test_reasoning_traces_with_implicit_dialog_rails_user_messages_only():
325325
engine: openai
326326
model: gpt-3.5-turbo-instruct
327327
reasoning_config:
328-
remove_thinking_traces: false
328+
remove_reasoning_traces: false
329329
""",
330330
colang_content="""
331331
define user express greeting
@@ -350,7 +350,7 @@ def test_reasoning_traces_with_bot_messages_only():
350350
engine: openai
351351
model: gpt-3.5-turbo-instruct
352352
reasoning_config:
353-
remove_thinking_traces: False
353+
remove_reasoning_traces: False
354354
""",
355355
colang_content="""
356356
define bot express greeting
@@ -377,12 +377,12 @@ def test_reasoning_traces_with_dedicated_task_models():
377377
engine: openai
378378
model: gpt-3.5-turbo-instruct
379379
reasoning_config:
380-
remove_thinking_traces: false
380+
remove_reasoning_traces: false
381381
- type: generate_user_intent
382382
engine: openai
383383
model: gpt-3.5-turbo-instruct
384384
reasoning_config:
385-
remove_thinking_traces: false
385+
remove_reasoning_traces: false
386386
rails:
387387
dialog:
388388
single_call:
@@ -398,7 +398,7 @@ def test_reasoning_traces_with_dedicated_task_models():
398398
exc_info.value
399399
)
400400
assert (
401-
"Please update your config.yml to set 'remove_thinking_traces: true' under reasoning_config"
401+
"Please update your config.yml to set 'remove_reasoning_traces: true' under reasoning_config"
402402
in str(exc_info.value)
403403
)
404404

@@ -414,15 +414,15 @@ def test_reasoning_traces_with_mixed_task_models():
414414
engine: openai
415415
model: gpt-3.5-turbo-instruct
416416
reasoning_config:
417-
remove_thinking_traces: false
417+
remove_reasoning_traces: false
418418
- type: generate_bot_message
419419
engine: openai
420420
model: gpt-3.5-turbo-instruct
421421
- type: generate_user_intent
422422
engine: openai
423423
model: gpt-3.5-turbo-instruct
424424
reasoning_config:
425-
remove_thinking_traces: false
425+
remove_reasoning_traces: false
426426
rails:
427427
dialog:
428428
single_call:
@@ -438,7 +438,7 @@ def test_reasoning_traces_with_mixed_task_models():
438438
exc_info.value
439439
)
440440
assert (
441-
"Please update your config.yml to set 'remove_thinking_traces: true' under reasoning_config"
441+
"Please update your config.yml to set 'remove_reasoning_traces: true' under reasoning_config"
442442
in str(exc_info.value)
443443
)
444444

@@ -457,15 +457,15 @@ def test_reasoning_traces_with_all_dialog_tasks():
457457
engine: openai
458458
model: gpt-3.5-turbo-instruct
459459
reasoning_config:
460-
remove_thinking_traces: false
460+
remove_reasoning_traces: false
461461
- type: generate_user_intent
462462
engine: openai
463463
model: gpt-3.5-turbo-instruct
464464
- type: generate_next_steps
465465
engine: openai
466466
model: gpt-3.5-turbo-instruct
467467
reasoning_config:
468-
remove_thinking_traces: false
468+
remove_reasoning_traces: false
469469
- type: generate_intent_steps_message
470470
engine: openai
471471
model: gpt-3.5-turbo-instruct
@@ -487,7 +487,7 @@ def test_reasoning_traces_with_all_dialog_tasks():
487487
)
488488
assert "Reasoning traces must be disabled for dialog rail tasks" in error_message
489489
assert (
490-
"Please update your config.yml to set 'remove_thinking_traces: true' under reasoning_config"
490+
"Please update your config.yml to set 'remove_reasoning_traces: true' under reasoning_config"
491491
in error_message
492492
)
493493

@@ -505,12 +505,12 @@ def test_reasoning_traces_with_dedicated_models_no_dialog_rails():
505505
engine: openai
506506
model: gpt-3.5-turbo-instruct
507507
reasoning_config:
508-
remove_thinking_traces: false
508+
remove_reasoning_traces: false
509509
- type: generate_user_intent
510510
engine: openai
511511
model: gpt-3.5-turbo-instruct
512512
reasoning_config:
513-
remove_thinking_traces: false
513+
remove_reasoning_traces: false
514514
""",
515515
)
516516

@@ -529,7 +529,7 @@ def test_reasoning_traces_with_implicit_dialog_rails_and_dedicated_models():
529529
engine: openai
530530
model: gpt-3.5-turbo-instruct
531531
reasoning_config:
532-
remove_thinking_traces: false
532+
remove_reasoning_traces: false
533533
""",
534534
colang_content="""
535535
define user express greeting
@@ -553,7 +553,7 @@ def test_reasoning_traces_with_implicit_dialog_rails_and_dedicated_models():
553553
exc_info.value
554554
)
555555
assert (
556-
"Please update your config.yml to set 'remove_thinking_traces: true' under reasoning_config"
556+
"Please update your config.yml to set 'remove_reasoning_traces: true' under reasoning_config"
557557
in str(exc_info.value)
558558
)
559559

@@ -569,7 +569,7 @@ def test_reasoning_traces_with_partial_dedicated_models():
569569
engine: openai
570570
model: gpt-3.5-turbo-instruct
571571
reasoning_config:
572-
remove_thinking_traces: false
572+
remove_reasoning_traces: false
573573
- type: generate_bot_message
574574
engine: openai
575575
model: gpt-3.5-turbo-instruct
@@ -587,7 +587,7 @@ def test_reasoning_traces_with_partial_dedicated_models():
587587
exc_info.value
588588
)
589589
assert (
590-
"Please update your config.yml to set 'remove_thinking_traces: true' under reasoning_config"
590+
"Please update your config.yml to set 'remove_reasoning_traces: true' under reasoning_config"
591591
in str(exc_info.value)
592592
)
593593

@@ -602,7 +602,7 @@ def test_reasoning_traces_with_implicit_dialog_rails_embeddings_only():
602602
engine: openai
603603
model: gpt-3.5-turbo-instruct
604604
reasoning_config:
605-
remove_thinking_traces: False
605+
remove_reasoning_traces: False
606606
rails:
607607
dialog:
608608
user_messages:
@@ -626,7 +626,7 @@ def test_reasoning_traces_with_bot_messages_embeddings_only():
626626
engine: openai
627627
model: gpt-3.5-turbo-instruct
628628
reasoning_config:
629-
remove_thinking_traces: False
629+
remove_reasoning_traces: False
630630
rails:
631631
dialog:
632632
user_messages:

0 commit comments

Comments
 (0)