Skip to content

fix(detectors): safely parse request_dump and response_dump JSON in SystemPromptLeakDetector - #627

Open
ojaswa072 wants to merge 1 commit into
GenAI-Security-Project:mainfrom
ojaswa072:fix/system-prompt-leak-parse-request-dump
Open

ojaswa072 wants to merge 1 commit into
GenAI-Security-Project:mainfrom
ojaswa072:fix/system-prompt-leak-parse-request-dump

Conversation

@ojaswa072

Copy link
Copy Markdown

Problem

ContextualLLMClient stores request_dump and response_dump as serialized JSON strings (.model_dump_json()) within the event payload. In SystemPromptLeakDetector._extract_texts, both fields were directly accessed as dictionaries (request_dump.get("messages"), response_dump.get("content")). When encountering string payloads, this resulted in an AttributeError or failure to extract system prompts and agent output, rendering system prompt leak challenges inoperative.

Fix

  • Added import json.
  • Safely deserialized request_dump and response_dump from JSON strings to dictionaries with exception guards (json.JSONDecodeError, TypeError).
  • Added fallback handling for None content values (message.get("content") or "").
  • Preserved existing dictionary handling for pre-parsed event objects.

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