Skip to content

fix: ImageConverter gracefully handles LLM API failures (fixes #1942) - #1948

Merged
Adam Fourney (afourney) merged 2 commits into
microsoft:mainfrom
hanhan761:fix-1942-image-llm-error-handling
Sep 3, 2026
Merged

Adam Fourney (afourney) merged 2 commits into
microsoft:mainfrom
hanhan761:fix-1942-image-llm-error-handling

Conversation

@hanhan761

Copy link
Copy Markdown
Contributor

Summary

ImageConverter._get_llm_description() crashes the entire conversion pipeline when the LLM API call fails (auth error, rate limit, network timeout). The API call at _image_converter.py:137 had no error handling.

This fix wraps the API call in a try/except block, matching the pattern already used by PptxConverter (lines 119-129). On failure, it returns None and the converter gracefully skips the LLM description while still returning extracted metadata.

Issue

Fixes #1942

Verification

  • 6/7 existing tests pass (1 pre-existing failure due to missing outlook dependency)
  • Conversion without LLM client works unchanged

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new failure-handling path needs regression test coverage.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Makes image conversion resilient to LLM API failures while preserving extracted metadata.

Changes:

  • Catches LLM request/response exceptions.
  • Skips unavailable image descriptions gracefully.
File summaries
File Description
_image_converter.py Adds LLM failure handling.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +137 to +140
try:
response = client.chat.completions.create(model=model, messages=messages)
return response.choices[0].message.content
except Exception:
@afourney
Adam Fourney (afourney) merged commit dd2df72 into microsoft:main Sep 3, 2026
3 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.

ImageConverter crashes when LLM API call fails (auth error, rate limit, etc.)

3 participants