Logging and Debugging Guardrails Generated Responses
This guide covers the various methods for logging, debugging, and understanding what happens during guardrails generation.
Overview
The NeMo Guardrails library provides multiple ways to inspect and debug guardrails generation:
Verbose Mode
Enable detailed console logging by setting verbose=True when creating the LLMRails instance:
This outputs detailed information about:
- LLM calls and their prompts/completions
- Rail activations and decisions
- Action executions
- Flow transitions
Explain Method
Get a quick summary of the last generation using the explain() method:
The ExplainInfo object provides methods to inspect:
- LLM calls summary
- Colang history
- Generated events
Generation Options: Log
For detailed structured logging, use the log generation option. This returns comprehensive information about what happened during generation.
Enabling Log Options
Log Option Reference
Response Structure
Using print_summary()
The log object has a print_summary() method for a human-readable overview:
Example output:
Accessing Detailed Data
Access specific log components programmatically:
Output Variables
Return specific context variables using the output_vars option:
Return Specific Variables
Return All Context Variables
Set output_vars to True to return the complete context:
Common Output Variables
Combining Log and Output Variables
Use both options together for comprehensive debugging:
Debugging Common Issues
Input Blocked Unexpectedly
Understanding Flow Execution
Analyzing LLM Performance
Server API Logging
When using the server API, include options in the request body:
Complete Debugging Example
Related Resources
- Tracing - Production monitoring and observability with OpenTelemetry