Skip to content

fix: fall back to stdlib mimetypes when puremagic returns empty#1391

Open
kostakost2 wants to merge 1 commit intosimonw:mainfrom
kostakost2:fix/mime-type-empty-string
Open

fix: fall back to stdlib mimetypes when puremagic returns empty#1391
kostakost2 wants to merge 1 commit intosimonw:mainfrom
kostakost2:fix/mime-type-empty-string

Conversation

@kostakost2
Copy link
Copy Markdown

Summary

Closes #1340.

When puremagic cannot identify a file type it may return an empty string instead of raising PureError. This empty string was passed through as the MIME type, causing attachment validation to fail with:

Error: This model does not support attachments of type ''

Changes

llm/utils.py:

  • mimetype_from_path(): treat empty puremagic results the same as PureError, then fall back to Python's mimetypes.guess_type() which handles common extensions (.mp4, .jpg, etc.) reliably
  • mimetype_from_string(): treat empty puremagic results as detection failure (returns None)

Test plan

  • test_mimetype_from_path_falls_back_to_stdlib — empty .mp4 file correctly detected as video/mp4
  • test_mimetype_from_path_returns_none_for_unknown — truly unknown extension returns None

🤖 Generated with Claude Code

When puremagic cannot identify a file type it may return an empty string
instead of raising PureError. This empty string was passed through as the
MIME type, causing attachment validation to fail with:

    Error: This model does not support attachments of type ''

Fix: treat empty puremagic results the same as PureError. For
mimetype_from_path, additionally fall back to Python's stdlib
mimetypes.guess_type() which handles common extensions (.mp4, .jpg, etc.)
reliably.

Closes simonw#1340

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

MIME type detection fails when puremagic returns empty string

1 participant