1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
37 small wins to finish your pathNext lesson →
rails.explain()
rails.explain() is the method that returns what the runtime did on the last call: every model call it made, with its task name, prompt, completion and token count.
Last updated: 30 Sep, 2026 · NeMo Guardrails 0.24.1
The Instructions lesson claimed the instructions reach the model on every call. explain() is how you check a claim like that, and every later lesson uses it to count calls.
Syntax:
info = rails.explain() # after a generate() call
info.print_llm_calls_summary() # one line per model call: task, time, tokens
info.llm_calls[0].prompt # the exact prompt sent
info.colang_history # the conversation as Colang eventsCalling explain after a turn
chat("What does SR-IOV do?")
info = rails.explain()Project files used on this pageThis lesson builds on a project from earlier lessons. The code below imports this file. Click a file to see its code, or follow the link to the lesson that wrote it. To run the code yourself, keep it in the same folder.
View the code here
config.yml
models:
- type: main
engine: openai
model: openai/gpt-oss-120b
api_key_env_var: GROQ_API_KEY
parameters:
base_url: https://api.groq.com/openai/v1
temperature: 0
instructions:
- type: general
content: |
You are an Enterprise IT Assistant specialising in Kubernetes,
Intel hardware, and enterprise networking.
Only answer questions about these topics.
Answer in one or two short sentences.
Reading the calls for one question
from nemoguardrails import LLMRails, RailsConfig
rails = LLMRails(RailsConfig.from_path("."))
def chat(message):
reply = rails.generate(messages=[{"role": "user", "content": message}])
print("User:", message)
print("Bot :", reply["content"])
chat("What does SR-IOV do?")
info = rails.explain()
info.print_llm_calls_summary()
print(info.llm_calls[0].prompt)Output
User: What does SR-IOV do? Bot : SR‑IOV (Single Root I/O Virtualization) lets a physical NIC present multiple virtual functions that can be directly assigned to VMs or containers, providing near‑bare‑metal network performance with low latency and reduced CPU overhead. Summary: 1 LLM call(s) took 0.68 seconds and used 201 tokens. 1. Task `general` took 0.68 seconds and used 201 tokens. You are an Enterprise IT Assistant specialising in Kubernetes, Intel hardware, and enterprise networking. Only answer questions about these topics. Answer in one or two short sentences. User: What does SR-IOV do? Assistant:
What explain showed
- One call, with the task named
general. With no Colang rules, NeMo sends the conversation to the model and returns the reply. - The prompt starts with the instructions from
config.yml, word for word, then the user's line andAssistant:. - The token count is what this turn cost on your Groq quota.
explain() vs the generation log
| rails.explain() | options={"log": ...} | |
|---|---|---|
| Covers | The last call on this object | The call it is passed to |
| Shows | Model calls and Colang history | Model calls, rails that ran, which rail stopped |
| Taught in | This lesson | Finding the rail that fired |
When you reach for it
- A reply is wrong and you want the prompt the model saw.
- Counting model calls per message, the cost of a config.
Watch out.
explain() describes the most recent generate on that LLMRails object only. Call it straight after the turn you want to read.Related
- Previous: Instructions that shape the answer
- Next: define user and define bot
- Reference: Logging
Try it yourself
- Print
info.llm_calls[0].completionand compare it with the reply. - Ask two questions in a row and check that explain only shows the second.
You understood something today that you didn't yesterday.