NeMo Guardrailsnemoguardrails 0.24.1 · Python 3.10+
Dashboard
0%
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:

python
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 events

Calling explain after a turn

python
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

ExampleAPI key
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)

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 and Assistant:.
  • The token count is what this turn cost on your Groq quota.

explain() vs the generation log

rails.explain()options={"log": ...}
CoversThe last call on this objectThe call it is passed to
ShowsModel calls and Colang historyModel calls, rails that ran, which rail stopped
Taught inThis lessonFinding 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.
Try it yourself
  • Print info.llm_calls[0].completion and 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.