1- # Copyright (c) 2025 Marco De Roni. All rights reserved.
1+ # Copyright (c) 2026 Marco De Roni. All rights reserved.
22# Licensed under the MIT License — see LICENSE file for details.
33
44import os
@@ -46,7 +46,8 @@ def generate_report(
4646 contract_name : str ,
4747 metadata : dict ,
4848 analysis : dict ,
49- output_dir : str
49+ output_dir : str ,
50+ pii_summary : dict = None
5051) -> str :
5152 """Genera un report Word professionale."""
5253
@@ -68,6 +69,30 @@ def generate_report(
6869
6970 doc .add_paragraph ()
7071
72+ # --- PII Redaction Summary ---
73+ if pii_summary and pii_summary .get ("total_entities" , 0 ) > 0 :
74+ add_heading (doc , "Privacy & PII Redaction Summary" , level = 1 )
75+ total = pii_summary .get ("total_entities" , 0 )
76+ breakdown = pii_summary .get ("breakdown" , {})
77+
78+ doc .add_paragraph (
79+ f"Before analysis, { total } sensitive entities were automatically "
80+ f"redacted and restored in this report."
81+ )
82+
83+ if breakdown :
84+ table = doc .add_table (rows = 1 , cols = 2 )
85+ table .style = "Table Grid"
86+ table .rows [0 ].cells [0 ].text = "Entity Type"
87+ table .rows [0 ].cells [1 ].text = "Count"
88+ for entity_type , count in sorted (breakdown .items ()):
89+ row = table .add_row ().cells
90+ row [0 ].text = entity_type
91+ row [1 ].text = str (count )
92+
93+ doc .add_paragraph ()
94+
95+ # --- Overall Risk ---
7196 overall = analysis .get ("overall_score" , "UNKNOWN" )
7297 add_heading (doc , "Overall Risk Assessment" , level = 1 )
7398 add_colored_paragraph (
@@ -77,6 +102,7 @@ def generate_report(
77102 )
78103 doc .add_paragraph ()
79104
105+ # --- Metadata ---
80106 add_heading (doc , "Contract Metadata" , level = 1 )
81107 table = doc .add_table (rows = 1 , cols = 2 )
82108 table .style = "Table Grid"
@@ -101,6 +127,7 @@ def generate_report(
101127
102128 doc .add_paragraph ()
103129
130+ # --- Missing Clauses ---
104131 add_heading (doc , "Missing Clauses" , level = 1 )
105132 missing = analysis .get ("missing_clauses" , [])
106133 if missing :
@@ -114,6 +141,7 @@ def generate_report(
114141
115142 doc .add_paragraph ()
116143
144+ # --- Clause Risk Analysis ---
117145 add_heading (doc , "Clause Risk Analysis" , level = 1 )
118146 findings = analysis .get ("findings" , {})
119147
0 commit comments