Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ def analyze_conversation(self, messages: List[Dict[str, Any]]) -> DetectionResul
detections = []
threat_count = 0
max_confidence = 0.0
# Highest confidence seen across ALL scanned (non-threat) messages, so
# the benign-case risk scaling below actually has something to scale.
max_scanner_confidence = 0.0

# Build conversation trace for LlamaFirewall
conversation_trace = []
Expand Down Expand Up @@ -303,6 +306,8 @@ def analyze_conversation(self, messages: List[Dict[str, Any]]) -> DetectionResul
threat_count += 1
max_confidence = max(max_confidence, confidence)
break # Stop on first threat (like scan_replay does)
else:
max_scanner_confidence = max(max_scanner_confidence, confidence)

except Exception as e:
logger.error(f"Error analyzing conversation with LlamaFirewall: {e}")
Expand Down Expand Up @@ -334,8 +339,8 @@ def analyze_conversation(self, messages: List[Dict[str, Any]]) -> DetectionResul
# For benign: convert scanner confidence to low malicious risk
# If scanners had some concerns (high confidence), slightly higher risk
# If scanners were very confident it's safe, very low risk
if max_confidence > 0:
confidence_score = max(0.1, min(0.3, max_confidence * 0.3)) # Scale to 0.1-0.3 range
if max_scanner_confidence > 0:
confidence_score = max(0.1, min(0.3, max_scanner_confidence * 0.3)) # Scale to 0.1-0.3 range
else:
confidence_score = 0.1 # No scanner concerns = very low risk

Expand Down