Execution rails: checking what an action returns
An execution rail checks what a tool or action handed back before the bot uses it. In version 0.24 with Colang 1.0 that is a flow, and the YAML key you may find online for it does nothing.
Checking a result before the bot speaks
define user ask order status
"Where is my order?"
"Has order A17 shipped?"
define bot report order
"Order $order_id is $status."
define bot unknown order
"I cannot find that order number."define flow order status
user ask order status
$order_id = execute find_order_id
$status = execute lookup_order(order_id=$order_id)
if $status == "unknown"
bot unknown order
stop
bot report orderThe flow calls two actions and keeps their results in variables with $, which is how one action's result reaches the next: $order_id goes into lookup_order. Before bot report order can put $status into a sentence, the flow checks it, and an unknown order gets its own reply.
import pretend_nemo
from nemoguardrails import LLMRails, RailsConfig
from config_actions import find_order_id, lookup_order
rails = LLMRails(RailsConfig.from_path("."))
rails.register_action(find_order_id, "find_order_id")
rails.register_action(lookup_order, "lookup_order")
for asked in ["Has order A17 shipped?", "Where is order Z01?"]:
print(asked, "->", rails.generate(messages=[{"role": "user", "content": asked}])["content"])Without the check, the second reply would have been Order Z01 is unknown., a sentence built from a value that was never meant for a customer.
The rails.execution key
from nemoguardrails import RailsConfig
from nemoguardrails.rails.llm.config import Rails
print(list(Rails.model_fields))
config = RailsConfig.from_content(yaml_content="""
rails:
execution:
flows:
- check tool output
""")
print(hasattr(config.rails, "execution"))NeMo's documentation shows rails: execution: flows: in its configuration reference. In 0.24.0 the rails section has no such field, and the configuration loads without a warning while the key is dropped. A rail configured that way never runs, and nothing tells you.
tool_input and tool_output are real fields. They run flows on tool calls a model makes and on the tool results sent back to it, so they apply when a model calls tools itself. The check above is for actions your own flows call.
- Add
B99to the questions and read which reply it gets. - Make
lookup_orderreturn an empty string for unknown orders and fix the flow to match. - Print
config.rails.model_dump()for the configuration with theexecutionkey.
Little by little, you're building something great.