Skip to content

Python tool for converting files and office documents to Markdown.

fix(pptx): ignore empty llm captions (#1886)

Lubrsy70033462f016
diff --git a/packages/markitdown/src/markitdown/converters/_pptx_converter.py b/packages/markitdown/src/markitdown/converters/_pptx_converter.py
index 21a12dc8..41ee5c04 100644
--- a/packages/markitdown/src/markitdown/converters/_pptx_converter.py
+++ b/packages/markitdown/src/markitdown/converters/_pptx_converter.py
@@ -147,7 +147,14 @@ class PptxConverter(DocumentConverter):
pass
# Prepare the alt, escaping any special characters
- alt_text = "\n".join([llm_description, alt_text]) or shape.name
+ alt_text = (
+ "\n".join(
+ text
+ for text in [llm_description, alt_text]
+ if text and text.strip()
+ )
+ or shape.name
+ )
alt_text = re.sub(r"[\r\n\[\]]", " ", alt_text)
alt_text = re.sub(r"\s+", " ", alt_text).strip()
diff --git a/packages/markitdown/tests/test_module_misc.py b/packages/markitdown/tests/test_module_misc.py
index 83fc05e9..148d094d 100644
--- a/packages/markitdown/tests/test_module_misc.py
+++ b/packages/markitdown/tests/test_module_misc.py
@@ -876,6 +876,31 @@ def test_exceptions() -> None:
assert type(exc_info.value.attempts[0].converter).__name__ == "PptxConverter"
+def test_pptx_converter_treats_none_llm_caption_as_empty(monkeypatch) -> None:
+ from markitdown.converters import _pptx_converter
+
+ calls = 0
+
+ def none_caption(*args, **kwargs):
+ nonlocal calls
+ calls += 1
+ return None
+
+ monkeypatch.setattr(_pptx_converter, "llm_caption", none_caption)
+
+ result = MarkItDown().convert(
+ os.path.join(TEST_FILES_DIR, "test.pptx"),
+ llm_client=MagicMock(),
+ llm_model="test-model",
+ )
+
+ assert calls > 0
+ assert (
+ "![This phrase of the caption is Human-written.](Picture4.jpg)"
+ in result.markdown
+ )
+
+
@pytest.mark.skipif(
skip_exiftool,
reason="do not run if exiftool is not installed",