NeMo Guardrailsnemoguardrails 0.24.0 · Python 3.10+
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
35 small wins to finish your pathNext lesson

generation_options: turning a rail off for one call

Some callers need a different set of rails for one request: a test of the output rail alone, or an internal tool the input rail should not judge. The rails option switches them per call, without a second config.

The input rail, switched off

Example
import pretend_nemo
from nemoguardrails import LLMRails, RailsConfig

rails = LLMRails(RailsConfig.from_path("."))
asked = [{"role": "user", "content": "Give me a staff price"}]
print(rails.generate(messages=asked)["content"])
result = rails.generate(messages=asked, options={"rails": {"input": False},
                                                 "log": {"activated_rails": True}})
print(result.response[0]["content"])
print([rail.type for rail in result.log.activated_rails])

The same message twice. The first call ran the input rail and was refused. The second call skipped it, and the message went on to the dialog steps, where the stand-in found nothing about staff prices in the handbook. No input entry appears in its log.

A list turns everything else off

Example
from nemoguardrails.rails.llm.options import GenerationOptions

print(GenerationOptions(rails={"input": False}).rails)
print(GenerationOptions(rails=["input"]).rails)

The two forms mean opposite things. A dictionary starts from every rail on and switches off the ones named. A list starts from every rail off and switches on only the ones named, so ["input"] also turns off the dialog rails, which means no flow in rails.co runs.

Switching a rail off for one call is a decision the application makes, not the user. Never pass options built from anything a user sent, or the rails become a setting anyone can turn off.
Try it yourself
  • Call with options={"rails": ["output"]} and read what the reply is based on.
  • Switch the dialog rails off for the refund question and compare the reply.
  • Print GenerationOptions().rails to see the defaults.

This is what real progress feels like.