Skip to content

fix(system-prompt-leak): handle assistant message content: null#254

Open
Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Jean-Regis-M:patch-16
Open

fix(system-prompt-leak): handle assistant message content: null#254
Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Jean-Regis-M:patch-16

Conversation

@Jean-Regis-M
Copy link

Summary

Fixes a crash in SystemPromptLeakDetector._extract_texts when an assistant message has "content": null.
The detector now gracefully treats null as empty string.

Problem

Issue #135: Test case DET‑SPL‑010 fails because the detector raises a TypeError on assistant messages with content: null.
This occurs in normal operation whenever an agent makes a tool call, effectively disabling the detector after the first such event.

Root Cause

In _extract_texts, the assistant branch uses:

llm_output += message.get("content", "")

Root cause:
When an assistant message contains "content": null (standard for tool-calling messages), 
message.get("content", "") returns None because the key exists. Concatenating None to 
a string raises TypeError, crashing the detector coroutine.

Solution:
Explicitly check for None before concatenation. If content is None, treat it as empty 
string. This preserves the original behaviour for all other cases and prevents the crash.

Impact:
- Minimal, isolated change (only the assistant branch).
- No side effects; all existing tests pass.
- Critical fix because most real agent traffic includes tool calls with null content, 
  which would otherwise silently disable the detector after the first such event.

Signed-off-by: JEAN REGIS <240509606@firat.edu.tr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant