Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions posthog/ai/sanitization.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ def sanitize_openai_image(item: Any) -> Any:
if not isinstance(item, dict):
return item

if item.get("type") == "input_image" and isinstance(item.get("image_url"), str):
return {
**item,
"image_url": redact_base64_data_url(item["image_url"]),
}

if (
item.get("type") == "image_url"
and isinstance(item.get("image_url"), dict)
Expand Down
19 changes: 19 additions & 0 deletions posthog/test/ai/test_sanitization.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,25 @@ def test_sanitize_openai(self):
)
self.assertEqual(result[0]["content"][1]["image_url"]["detail"], "high")

def test_sanitize_openai_input_image(self):
input_data = [
{
"role": "user",
"content": [
{
"type": "input_image",
"image_url": self.sample_base64_image,
}
],
}
]

result = sanitize_openai(input_data)

self.assertEqual(
result[0]["content"][0]["image_url"], REDACTED_IMAGE_PLACEHOLDER
)

def test_sanitize_openai_preserves_regular_urls(self):
input_data = [
{
Expand Down
Loading