Implementation:Protectai Modelscan ConsoleReport Generate
Appearance
| Knowledge Sources | |
|---|---|
| Domains | ML_Security, Reporting |
| Last Updated | 2026-02-14 12:00 GMT |
Overview
Concrete tool for generating formatted scan reports (console and JSON) provided by the modelscan reports module.
Description
The ConsoleReport and JSONReport classes implement the Report abstract base class to produce scan output in two built-in formats. ConsoleReport uses the rich library to print color-coded, severity-grouped issue lists to the terminal. JSONReport serializes the complete results dictionary to JSON, optionally writing to a file. Both are loaded dynamically by ModelScan.generate_report() via the reporting.module setting.
Usage
Use these report classes when you need to:
- Display interactive scan results in a terminal (ConsoleReport)
- Export scan results as structured JSON for pipeline processing (JSONReport)
- Write scan results to a file for audit purposes (JSONReport with output_file)
- Build a custom report class following the same interface
Code Reference
Source Location
- Repository: modelscan
- File: modelscan/reports.py
- Lines: L14-98
Signature
class Report(metaclass=abc.ABCMeta):
@staticmethod
def generate(
scan: ModelScan,
settings: Dict[str, Any] = {},
) -> Optional[str]:
"""Abstract method. Generate report for completed scan."""
class ConsoleReport(Report):
@staticmethod
def generate(
scan: ModelScan,
settings: Dict[str, Any] = {},
) -> None:
"""
Print rich-formatted console report.
Args:
scan: Completed ModelScan instance with issues, errors, skipped.
settings: Report settings dict. Keys:
- show_skipped (bool): Include skipped files in output.
"""
class JSONReport(Report):
@staticmethod
def generate(
scan: ModelScan,
settings: Dict[str, Any] = {},
) -> None:
"""
Print JSON report to stdout and optionally to file.
Args:
scan: Completed ModelScan instance.
settings: Report settings dict. Keys:
- show_skipped (bool): Include skipped files in output.
- output_file (str): Optional file path to write JSON report.
"""
Import
from modelscan.reports import ConsoleReport, JSONReport
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| scan | ModelScan | Yes | Completed ModelScan instance with populated issues, errors, skipped, and scanned attributes |
| settings | Dict[str, Any] | No | Report-specific settings: show_skipped (bool), output_file (str, JSONReport only) |
Outputs
| Name | Type | Description |
|---|---|---|
| ConsoleReport output | stdout | Rich-formatted text printed to terminal: summary section with issue counts by severity, issues grouped by severity with details, errors section, and optionally skipped files |
| JSONReport output | stdout + optional file | JSON-serialized results dict printed to stdout. If output_file is set, also written to the specified file path |
Usage Examples
Console Report via ModelScan
from modelscan.modelscan import ModelScan
scanner = ModelScan()
scanner.scan("/path/to/model.pkl")
# Uses ConsoleReport by default
scanner.generate_report()
JSON Report with File Output
from modelscan.modelscan import ModelScan
scanner = ModelScan()
scanner.scan("/path/to/model.pkl")
# Switch to JSON reporting with file output
scanner._settings["reporting"]["module"] = "modelscan.reports.JSONReport"
scanner._settings["reporting"]["settings"] = {
"show_skipped": True,
"output_file": "/tmp/scan_report.json",
}
scanner.generate_report()
Direct ConsoleReport Usage
from modelscan.modelscan import ModelScan
from modelscan.reports import ConsoleReport
scanner = ModelScan()
scanner.scan("/path/to/model.pkl")
# Call ConsoleReport directly
ConsoleReport.generate(scan=scanner, settings={"show_skipped": False})
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment