Skip to content

fix: Apply guardrails transformations to LLM inputs and bot outputs. - #1297

Merged
Pouyanpi merged 3 commits into
NVIDIA-NeMo:developfrom
pangeacyber:feature/fix-v2-transformations
Aug 18, 2025
Merged

fix: Apply guardrails transformations to LLM inputs and bot outputs.#1297
Pouyanpi merged 3 commits into
NVIDIA-NeMo:developfrom
pangeacyber:feature/fix-v2-transformations

Conversation

@lapinek

@lapinek lapinek commented Jul 18, 2025

Copy link
Copy Markdown
Contributor

Description

Currently, when input and output rails process (that is, transform or redact) user and bot messages, the processed versions are not used:

  • LLM flows use original $event.final_transcript instead of processed $user_message.
  • Bot utterances use the original $text instead of processed $bot_message.
  • This allowed sensitive, unfiltered data to leak to LLM and users despite guardrails.

To reproduce, you can run this config against the current develop (requires OPENAI_API_KEY):

#config.yml

colang_version: "2.x"

models:
  - type: main
    engine: openai
    model: gpt-4o-mini
# main

import core
import llm
import guardrails

flow input rails $input_text
    global $user_message
    $user_message = "{$input_text}, Dick"

flow output rails $output_text
    global $bot_message
    $bot_message = "{$output_text}, and Harry"

flow main
  activate llm continuation
poetry run nemoguardrails chat --config /path/to/config
> Echo this: Tom  

Expected output:

Tom, Dick, and Harry

Actual output:

Tom

With patch provided in this PR, the output should be:

Tom, Dick., and Harry

Related Issue(s)

Mentions

@schuellc-nvidia, @drazvan - since you’ve contributed most to the affected files, your review would be much appreciated!

Checklist

  • I've read the CONTRIBUTING guidelines.
  • I've updated the documentation if applicable.
  • I've added tests if applicable.
  • @mentions of the person or team responsible for reviewing proposed changes.

@lapinek
lapinek force-pushed the feature/fix-v2-transformations branch 2 times, most recently from 9e9d8f6 to 97871a5 Compare July 19, 2025 23:06
@lapinek

lapinek commented Jul 21, 2025

Copy link
Copy Markdown
Contributor Author

In addition to the provided example and test, you can observe the unfixed behavior in the following branches (we’re planning to open PRs for these as well):

@schuellc-nvidia

schuellc-nvidia commented Jul 22, 2025

Copy link
Copy Markdown
Collaborator

Thank you @lapinek, will take a look!
@Pouyanpi Can you also take a look at this!

@github-actions

Copy link
Copy Markdown
Contributor

Documentation preview

https://nvidia.github.io/NeMo-Guardrails/review/pr-1297

@codecov-commenter

codecov-commenter commented Jul 22, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (develop@0d6fa42). Learn more about missing BASE report.
⚠️ Report is 25 commits behind head on develop.

Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #1297   +/-   ##
==========================================
  Coverage           ?   70.70%           
==========================================
  Files              ?      161           
  Lines              ?    16312           
  Branches           ?        0           
==========================================
  Hits               ?    11533           
  Misses             ?     4779           
  Partials           ?        0           
Flag Coverage Δ
python 70.70% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@schuellc-nvidia schuellc-nvidia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good to me!

Ideally, we would also have a test that involves the flows generating user intent for unhandled user utterance and continuation on unhandled user utterance that are affected by it.

@lapinek

lapinek commented Jul 22, 2025

Copy link
Copy Markdown
Contributor Author

Changes look good to me!

Ideally, we would also have a test that involves the flows generating user intent for unhandled user utterance and continuation on unhandled user utterance that are affected by it.

@schuellc-nvidia, thank you for the review!

Would it be OK if we add these tests in a follow-up? I'd like to take a closer look at the dialog flows first to ensure meaningful coverage. I believe the already included test verifies that the rails transformations are applied. We're relying on this behavior in upcoming PRs.

Update:

@schuellc-nvidia

Copy link
Copy Markdown
Collaborator

Changes look good to me!
Ideally, we would also have a test that involves the flows generating user intent for unhandled user utterance and continuation on unhandled user utterance that are affected by it.

@schuellc-nvidia, thank you for the review!

Would it be OK if we add these tests in a follow-up? I'd like to take a closer look at the dialog flows first to ensure meaningful coverage. I believe the already included test verifies that the rails transformations are applied. We're relying on this behavior in upcoming PRs.

Update:

Yes, that's fine with me.

@Pouyanpi Pouyanpi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @lapinek , this is a critical security fix with solid implementation 👍🏻 It is ready to merge 🚀

Would you please gpg sign your commits following contributing guidelines?

- Use processed $user_message instead of raw $event.final_transcript in LLM inputs.
- Use processed $bot_message instead of raw $text in bot outputs.
- Prevent sensitive or unfiltered data from reaching the LLM or users by correctly applying input/output rails transformations.
@lapinek
lapinek force-pushed the feature/fix-v2-transformations branch from c1471c1 to 48db267 Compare August 15, 2025 16:41
@lapinek

lapinek commented Aug 15, 2025

Copy link
Copy Markdown
Contributor Author

@Pouyanpi, thanks for your review! I've signed the commits.

The reason I initially used "Signed-of-by..." was that it seemed like a valid alternative according to the contribution guidelines: https://github.com/NVIDIA/NeMo-Guardrails/blob/52ac7edc18e5b6fb1900b639b5c6734dca09b918/CONTRIBUTING.md#summary. Since GPG signature is required, maybe that wording could be more explicit. But I am happy to sign, no problem 🙂

@Pouyanpi
Pouyanpi merged commit 00a9610 into NVIDIA-NeMo:develop Aug 18, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants