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
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
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.
- 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().railsto see the defaults.
This is what real progress feels like.