Skip to content

Conversation

@vikas5914
Copy link

@vikas5914 vikas5914 commented Dec 7, 2025

Summary

  1. Extend sanitize_openai_image to redact base64 data when OpenAI’s Responses API sends input_image items where image_url is a string (as documented here).

  2. Restore the regression test for that payload format so we cover both dict-style image_url objects and string URLs.
    The previous check only handled { "type": "image_url", "image_url": { "url": ... } }. But OpenAI also allows:

{
    "type": "input_image",
    "image_url": f"data:image/jpeg;base64,{base64_image}",
}

Example from the official docs:

from openai import OpenAI

client = OpenAI()

response = client.responses.create(
    model="gpt-4.1-mini",
    input=[{
        "role": "user",
        "content": [
            {"type": "input_text", "text": "what's in this image?"},
            {
                "type": "input_image",
               "image_url": f"data:image/jpeg;base64,{base64_image}",
            },
        ],
    }],
)

print(response.output_text)

Without this fix, base64 strings in that shape weren’t redacted.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Comments (1)

  1. posthog/ai/sanitization.py, line 99-102 (link)

    style: inconsistent type checking - sanitize_openai_image checks isinstance(item.get("image_url"), str) but this function only checks "image_url" in item

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@vikas5914
Copy link
Author

@ablaszkiewicz Sorry for tagging you but any chance to review this?

@ablaszkiewicz ablaszkiewicz requested review from a team and removed request for a team December 11, 2025 09:00
@ablaszkiewicz
Copy link
Contributor

lgtm ✅ Python pipeline is currently broken. We are fixing it

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.

2 participants