-
Couldn't load subscription status.
- Fork 553
feat!: add support for preserving and optionally applying guardrails to reasoning traces #1145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
ab96ab6 to
25a0d2b
Compare
|
I feel uneasy about the way result = self.llm_task_manager.parse_task_output(…)
text = result.text # this is new before `result` was plain str
# …then all kinds of ad-hoc cleaning: .strip(), strip_quotes(),
# get_first_nonempty_line(), get_multiline_response(), split("\n"), etc.all over the place. We end up with:
We MUST stop inlining dozens of little string hacks in every action. |
|
This module |
5f2416e to
119854a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm good with this, just add some more tests for unexpected patterns that might look like reasoning traces but aren't.
e0a4c98 to
63b0fa8
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1145 +/- ##
===========================================
+ Coverage 68.06% 68.19% +0.13%
===========================================
Files 161 161
Lines 15822 15905 +83
===========================================
+ Hits 10769 10847 +78
- Misses 5053 5058 +5
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
ce89a19 to
a6138f9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The heavy lifting in this MR looks good. There are some minor fixes, but I have not seen anything major that needs to be improved. Nice job!
- Updated all instances to use `result.text` for accessing parsed task output text. - Replaced direct usage of `result` with `text` where applicable for clarity and consistency. - Adjusted related logic to ensure proper handling of stripped and formatted text.
Added logic to prepend `reasoning_trace` to the `content` of the response if available. This ensures that reasoning traces are included in the output for better traceability and debugging. BREAKING CHANGE: Modifies the response structure by including `reasoning_trace` in the `content` field when applicable. feat(llm): add support for reasoning traces in output Implemented `_process_parsed_output` to handle reasoning traces in LLM outputs. Added `_should_guardrail_reasoning_traces` and `_get_guardrail_reasoning_traces` for configuration-based trace inclusion. refactor(llm): simplify reasoning traces and threshold logic refactor(llm): streamline output processing and trace handling - Added `text.strip()` to clean up leading/trailing spaces in outputs. - Replaced `text` with `result` for consistent variable naming. - Refactored `_process_parsed_output` to separate trace recording and response assembly. - Introduced `_record_reasoning_trace` and `_assemble_response` for modularity and clarity. add tests for reasoning traces processing - Added `TestProcessParsedOutput` to validate `_process_parsed_output` behavior with and without reasoning traces. - Added `TestGuardrailReasoningTraces` to test guardrail reasoning traces configuration. - Updated imports to include `_process_parsed_output` and `_get_guardrail_reasoning_traces`. refactor(tests): rename parameter for clarity in tests - Updated `_process_parsed_output` parameter from `guardrail_reasoning_traces` to `include_reasoning_trace`. - Adjusted test cases to reflect the new parameter name for better readability and consistency. fix: ensure reasoning_trace_var is cleared and test isolation fix(config): correct dialog rails activation logic Fixed the `has_dialog_rails` logic in `RailsConfig` to require both `user_messages` and `bot_messages` for implicit activation. Removed `flows` from the condition to align with expected behavior. test(config): adjust tests for updated dialog rails logic Modified test cases to reflect the corrected dialog rails activation logic. add reasoning trace context variable correct ContextVar type annotation add default value to reasoning_trace_var
review: improve apply_to_reasoning_traces description
0042ed3 to
0e34af6
Compare
Summary Generated by Copilot
This pull request introduces enhancements to the LLM generation pipeline by adding support for reasoning traces and improving the handling of parsed task outputs. Key changes include the introduction of new utility functions, updates to existing methods to process reasoning traces, and modifications to ensure consistent handling of parsed outputs across various LLM tasks.
Enhancements to Reasoning Trace Support:
reasoning_trace_varto store reasoning traces and utility functions such as_record_reasoning_trace,_assemble_response, and_process_parsed_outputto manage reasoning traces and integrate them into responses. (nemoguardrails/context.py[1]nemoguardrails/actions/llm/generation.py[2]_get_apply_to_reasoning_tracesto fetch configuration values for including reasoning traces in outputs, and_include_reasoning_tracesto encapsulate this logic. (nemoguardrails/actions/llm/generation.pynemoguardrails/actions/llm/generation.pyR1384-R1387)Consistent Handling of Parsed Outputs:
generate_user_intent,generate_bot_message,generate_value) to extract and use thetextproperty fromParsedTaskOutputobjects for consistency. (nemoguardrails/actions/llm/generation.py[1] [2] [3]generate_bot_messageandgenerate_intent_steps_message. (nemoguardrails/actions/llm/generation.py[1] [2]Utility and Structural Improvements:
ReasoningExtractionResultas adataclassto encapsulate cleaned text and reasoning traces extracted from LLM outputs. (nemoguardrails/llm/filters.pynemoguardrails/llm/filters.pyL18-R36)get_and_clear_reasoning_traceto retrieve and clear reasoning traces from the context. (nemoguardrails/actions/llm/utils.pynemoguardrails/actions/llm/utils.pyR580-R591)Updates to Other LLM Modules:
nemoguardrails/library/content_safety/actions.py[1]nemoguardrails/library/self_check/facts/actions.py[2]These changes collectively enhance the flexibility and traceability of LLM outputs, improving both debugging capabilities and the overall user experience.
Impact
tldr;
this feature ensures that reasoning traces are always returned to the user. Removing it would affect internals of nemoguardrails, but not the output that users receive.
Interaction between apply_to_reasoning_traces and remove_thinking_traces:
reasoning_trace_varconditional response inclusion:
visible vs. stored output:
implementation details:
_assemble_response(text, trace, include_reasoning) controls this behavior
Returns trace + text when include_reasoning is TRUE
Returns just text when include_reasoning is FALSE
Flow control: The decision happens in _process_parsed_output() where both storage and assembly occur
requires #1161