Console Reporter¶
Console Reporter outputs beautifully colored validation results to the terminal using the Rich library.
Basic Usage¶
from truthound.reporters import get_reporter
reporter = get_reporter("console")
output = reporter.render(validation_result)
print(output)
# Or print directly
reporter.print(validation_result)
Configuration Options¶
ConsoleReporterConfig provides the following options:
| Option | Type | Default | Description |
|---|---|---|---|
color |
bool |
True |
Enable ANSI color output |
width |
int \| None |
None |
Output width (None = terminal width) |
show_header |
bool |
True |
Display header section |
show_summary |
bool |
True |
Display summary statistics |
show_issues_table |
bool |
True |
Display issues table |
compact |
bool |
False |
Compact mode (brief output) |
severity_colors |
dict[str, str] |
Default color map | Colors per severity |
Default Severity Colors¶
DEFAULT_SEVERITY_COLORS = {
"critical": "bold red",
"high": "red",
"medium": "yellow",
"low": "green",
"info": "blue",
}
Usage Examples¶
Basic Usage¶
from truthound.reporters import get_reporter
from truthound.reporters.console_reporter import ConsoleReporterConfig
# Default settings
reporter = get_reporter("console")
output = reporter.render(result)
# Custom settings
config = ConsoleReporterConfig(
color=True,
width=120,
compact=False,
show_issues_table=True,
)
reporter = get_reporter("console", **config.__dict__)
Compact Mode¶
Compact mode outputs a single-line summary:
Or on failure:
Disable Colors¶
Colors can be disabled for CI environments or file output:
Direct Terminal Output¶
The print() method outputs directly to the terminal via Rich Console:
Output Format¶
Full Output (Default)¶
╭─────────────────────────────────────────────────────────────╮
│ Truthound Validation Report │
╰─────────────────────────────────────────────────────────────╯
Data Asset: customer_data.csv
Run ID: abc123-def456
Status: FAILED
Timestamp: 2024-01-15 10:30:45
┌──────────────────────────────────────────────────────────────┐
│ Summary │
├──────────────────────────────────────────────────────────────┤
│ Total Validators: 10 │
│ Passed: 8 │
│ Failed: 2 │
│ Pass Rate: 80.0% │
│ Execution Time: 0.05s │
└──────────────────────────────────────────────────────────────┘
Issues by Severity:
🔴 Critical: 1
🟠 High: 1
🟡 Medium: 0
🟢 Low: 0
┌──────────────┬──────────┬───────────┬─────────────────────────┐
│ Validator │ Column │ Severity │ Message │
├──────────────┼──────────┼───────────┼─────────────────────────┤
│ NullValidator│ email │ critical │ 5 null values found │
│ RangeValidator│ age │ high │ 3 values out of range │
└──────────────┴──────────┴───────────┴─────────────────────────┘
Class Attributes¶
API Reference¶
ConsoleReporter¶
class ConsoleReporter(ValidationReporter[ConsoleReporterConfig]):
"""Rich-based console reporter."""
def render(self, data: ValidationResult) -> str:
"""Render validation result as string."""
...
def print(self, data: ValidationResult) -> None:
"""Print validation result directly to terminal."""
...
def render_compact(self, data: ValidationResult) -> str:
"""Render compact single-line summary."""
...
Dependencies¶
Console Reporter uses the Rich library:
Rich is included in Truthound's default dependencies.