Skip to content

Commit 410fb36

Browse files
committed
Add PII redaction report and audit log improvements
1 parent 5e405bc commit 410fb36

3 files changed

Lines changed: 40 additions & 5 deletions

File tree

audit_log.jsonl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
{"timestamp": "2026-04-21T23:35:47.632246", "contract": "Lic_Online_TOMA_v062223_CH_CA_ENG.pdf", "overall_score": "RED", "missing_clauses": ["Gross Negligence / Wilful Misconduct Carve-out"], "governing_law": "Swiss law without reference to its confli", "notice_period": "Not detected", "hash": "f2eb3a487f9aa3945ea19a4ed68986e358eb0e37b1d1a0c00eb4b5c9aa60b2ce"}
2+
{"timestamp": "2026-04-21T23:41:05.008016", "contract": "Lic_Online_TOMA_v062223_CH_CA_ENG.pdf", "overall_score": "RED", "missing_clauses": ["Gross Negligence / Wilful Misconduct Carve-out"], "governing_law": "Swiss law without reference to its confli", "notice_period": "Not detected", "hash": "80c23387048a6a995ed11b26876bb2f7a8c65987a617a0835ddf04345ca7263f"}

main.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ def scan_contract(path: str, rules: dict) -> dict:
4343
print(f" → {len(clauses)} sezioni rilevate")
4444

4545
# Sanitize PII
46+
pii_mapping = {}
4647
try:
47-
from scanner.sanitizer import sanitize, desanitize
48+
from scanner.sanitizer import sanitize
4849
text, pii_mapping = sanitize(text)
4950
print(f" → PII sanitizzato: {len(pii_mapping)} entità redatte")
5051
except Exception as e:
51-
pii_mapping = {}
5252
print(f" → PII sanitization skipped: {e}")
5353

5454
print(" → Estrazione metadati...")
@@ -57,8 +57,14 @@ def scan_contract(path: str, rules: dict) -> dict:
5757
print(" → Analisi clausole...")
5858
analysis = analyze(text, clauses, rules)
5959

60+
# Build PII summary
61+
pii_summary = {"total_entities": len(pii_mapping), "breakdown": {}}
62+
for placeholder in pii_mapping.keys():
63+
entity_type = placeholder.split("_")[0].replace("[", "")
64+
pii_summary["breakdown"][entity_type] = pii_summary["breakdown"].get(entity_type, 0) + 1
65+
6066
print(" → Generazione report Word...")
61-
report_path = generate_report(name, metadata, analysis, OUTPUT_DIR)
67+
report_path = generate_report(name, metadata, analysis, OUTPUT_DIR, pii_summary=pii_summary)
6268

6369
# Audit log
6470
try:

scanner/reporter.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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

44
import 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

Comments
 (0)