NeMo-Guardrails
NeMo-Guardrails copied to clipboard
How to modify the user input message before it goes through a given flow
I want to perform a preprocessing step in some flows. How can I modify the user input message across these flows? Specifically, I aim to alter the last_user_message and proceed with the flow as usual. I attempted to modify it in place by executing an action and setting the returned message to last_user_message using $last_user_message = execute my_action(new_user_message=$last_user_message). However, when the request reaches my LLM, the original message is still being passed through.
Hi @msalhab96 !
The way to achieve this is to define an input rail flow which changes the $user_message variable, not $last_user_message. See a quick example in this test: https://github.com/NVIDIA/NeMo-Guardrails/blob/develop/tests/test_input_ouput_rails_no_dialog.py (where "!" is appended to the input).
@drazvan Thanks for you response,
I'm wondering, is there any way to apply this to only specific flow? I mean if I use input rail flow it's going to preprocess the input message before it goes to any flow, but I want to do that in a specific flows not all of them.
You could set a context variable in your flow, and use that to conditionally trigger the logic in the input flow:
define flow your flow
user some intent
$mark_in_your_flow = True
...
$mark_in_your_flow = False
define flow the input rail flow
if $mark_in_your_flow
...
$user_message = ...