Skip to content

fix(media): inspect_document names the image format from its bytes and skips files it cannot read - #344

Merged
chigwell merged 1 commit into
chigwell:mainfrom
axisrow:fix/inspect-document-mime
Oct 21, 2026
Merged

chigwell merged 1 commit into
chigwell:mainfrom
axisrow:fix/inspect-document-mime

Conversation

@axisrow

@axisrow axisrow commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Two problems in inspect_document's image path:

  1. The image format was derived from the declared mime type / filename extension, but those are untrustworthy — a GIF sent as smile.jpg, or a HEIC/BMP scan, produced a media type the Claude API rejects with an opaque error.
  2. Unsupported files were downloaded into memory before being told apart, even though nothing downstream could read them.

The format is now sniffed from the file signature (_sniff_image_format: PNG / JPEG / GIF / WebP) and an explicit readable message names the actual format when the bytes are not a viewable image. The format/type/ext triage happens before download, so unsupported formats are refused without transferring the file. Behavior for PDF and text paths is unchanged (same checks, hoisted above the download).

Testing

  • tests/test_inspect_document.py covers signature sniffing (incl. mismatched extension) and the pre-download refusal.
  • Full suite: 1414 passed.

🤖 Generated with Claude Code

…d skips files it cannot read

Every image/* file was returned as image/jpeg unless it was a PNG or WebP, so a GIF, BMP or HEIC reached the Claude API with the wrong media type and was rejected. Detect the format from the file signature and refuse formats the API cannot take with an explanation. Files that are not an image, PDF or text file were downloaded completely only to be told they are unsupported; classify first and skip the download.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018Xun6C4mXUAKbVSmiEEh79
@chigwell
chigwell merged commit b52389d into chigwell:main Oct 21, 2026
4 checks passed
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.

3 participants