From 3736d32ec47b7f8fef2ddddf9db68423d935e4b4 Mon Sep 17 00:00:00 2001 From: Denys Moskalenko Date: Mon, 3 Nov 2025 18:21:54 +0100 Subject: [PATCH] Add support for detecting and handling `application/msword` files. --- pydantic_ai_slim/pydantic_ai/messages.py | 6 ++++++ tests/test_messages.py | 2 ++ 2 files changed, 8 insertions(+) diff --git a/pydantic_ai_slim/pydantic_ai/messages.py b/pydantic_ai_slim/pydantic_ai/messages.py index 5c38860eec..21dc9df240 100644 --- a/pydantic_ai_slim/pydantic_ai/messages.py +++ b/pydantic_ai_slim/pydantic_ai/messages.py @@ -34,6 +34,7 @@ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'text/html', 'text/markdown', + 'application/msword', 'application/vnd.ms-excel', ] VideoMediaType: TypeAlias = Literal[ @@ -434,8 +435,12 @@ def _infer_media_type(self) -> str: return 'application/pdf' elif self.url.endswith('.rtf'): return 'application/rtf' + elif self.url.endswith('.doc'): + return 'application/msword' elif self.url.endswith('.docx'): return 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' + elif self.url.endswith('.xls'): + return 'application/vnd.ms-excel' elif self.url.endswith('.xlsx'): return 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' @@ -645,6 +650,7 @@ class ToolReturn: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'xlsx', 'text/html': 'html', 'text/markdown': 'md', + 'application/msword': 'doc', 'application/vnd.ms-excel': 'xls', } _audio_format_lookup: dict[str, AudioFormat] = { diff --git a/tests/test_messages.py b/tests/test_messages.py index 8508648d44..6ced1396cd 100644 --- a/tests/test_messages.py +++ b/tests/test_messages.py @@ -147,6 +147,7 @@ def test_binary_content_video(media_type: str, format: str): ('application/pdf', 'pdf'), ('text/plain', 'txt'), ('text/csv', 'csv'), + ('application/msword', 'doc'), ('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'docx'), ('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'xlsx'), ('text/html', 'html'), @@ -209,6 +210,7 @@ def test_image_url_invalid(): pytest.param(DocumentUrl('foobar.pdf'), 'application/pdf', 'pdf', id='pdf'), pytest.param(DocumentUrl('foobar.txt'), 'text/plain', 'txt', id='txt'), pytest.param(DocumentUrl('foobar.csv'), 'text/csv', 'csv', id='csv'), + pytest.param(DocumentUrl('foobar.doc'), 'application/msword', 'doc', id='doc'), pytest.param( DocumentUrl('foobar.docx'), 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',