langchain - 💡(How to fix) Fix ChatMistralAI: Add Image Input Support [1 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langchain-ai/langchain#37007Fetched 2026-04-26 05:05:52
View on GitHub
Comments
1
Participants
1
Timeline
5
Reactions
0
Participants
Timeline (top)
labeled ×3commented ×1issue_type_added ×1

Code Example

def _convert_lc_image_block_to_mistral(block: dict) -> dict:
    """Convert a LangChain ImageContentBlock to Mistral's image_url format."""
    if block.get("type") != "image":
        return block
    if url := block.get("url"):
        return {"type": "image_url", "image_url": url}
    if base64_data := block.get("base64"):
        mime_type = block.get("mime_type")
        return {"type": "image_url", "image_url": f"data:{mime_type};base64,{base64_data}"}
    raise ValueError("Image content block must have either url or base64 field set"
RAW_BUFFERClick to expand / collapse

Submission checklist

  • This is a feature request, not a bug report or usage question.
  • I added a clear and descriptive title that summarizes the feature request.
  • I used the GitHub search to find a similar feature request and didn't find it.
  • I checked the LangChain documentation and API reference to see if this feature already exists.
  • This is not related to the langchain-community package.

Package (Required)

  • langchain
  • langchain-openai
  • langchain-anthropic
  • langchain-classic
  • langchain-core
  • langchain-model-profiles
  • langchain-tests
  • langchain-text-splitters
  • langchain-chroma
  • langchain-deepseek
  • langchain-exa
  • langchain-fireworks
  • langchain-groq
  • langchain-huggingface
  • langchain-mistralai
  • langchain-nomic
  • langchain-ollama
  • langchain-openrouter
  • langchain-perplexity
  • langchain-qdrant
  • langchain-xai
  • Other / not sure / general

Feature Description

I would like ChatMistralAI to support image inputs via the standard ImageContentBlock class and the create_image_block helper methods.

LangChain defines a standard ImageContentBlock format for multimodal messages, but ChatMistralAI forwards it to the Mistral API without converting it. Since Mistral expects a different image schema, this leads to API errors when using helpers like create_image_block or ImageContentBlock.

CaseMistral Expected FormatLangChain (ImageContentBlock) Format
Image URL{ "type": "image_url", "image_url": "https://..." }{ "type": "image", "url": "https://..." }
Base64 Image{ "type": "image_url", "image_url": "data:<mime_type>;base64,<b64_data>" }{ "type": "image", "base64": "<b64_data>", "mime_type": "image/png" }

Use Case

I'm trying to use the ImageContentBlock class & the create_image_block method from langchain to pass images as input to vision models from different providers. But since Mistral models have a custom image input format, I end up with a custom conversion layer just for Mistral models.

If ChatMistralAI natively supports image input with the standard image content blocks, then it would be very useful as I will not have to have a custom conversion layer just for Mistral models.

Proposed Solution

I think we can have a conversion method for image content blocks like this:

def _convert_lc_image_block_to_mistral(block: dict) -> dict:
    """Convert a LangChain ImageContentBlock to Mistral's image_url format."""
    if block.get("type") != "image":
        return block
    if url := block.get("url"):
        return {"type": "image_url", "image_url": url}
    if base64_data := block.get("base64"):
        mime_type = block.get("mime_type")
        return {"type": "image_url", "image_url": f"data:{mime_type};base64,{base64_data}"}
    raise ValueError("Image content block must have either url or base64 field set"

Alternatives Considered

No response

Additional Context

No response

extent analysis

TL;DR

Implement a conversion method to transform LangChain's ImageContentBlock into Mistral's expected image format.

Guidance

  • Identify the image type in the ImageContentBlock and convert it accordingly to match Mistral's format.
  • Use the proposed _convert_lc_image_block_to_mistral method as a starting point for the conversion logic.
  • Ensure the conversion method handles both URL and base64 image formats.
  • Integrate the conversion method into the ChatMistralAI codebase to enable native support for image inputs.

Example

def _convert_lc_image_block_to_mistral(block: dict) -> dict:
    """Convert a LangChain ImageContentBlock to Mistral's image_url format."""
    if block.get("type") != "image":
        return block
    if url := block.get("url"):
        return {"type": "image_url", "image_url": url}
    if base64_data := block.get("base64"):
        mime_type = block.get("mime_type")
        return {"type": "image_url", "image_url": f"data:{mime_type};base64,{base64_data}"}
    raise ValueError("Image content block must have either url or base64 field set")

Notes

The proposed solution assumes that the ImageContentBlock will always contain either a URL or base64 data. Additional error handling may be necessary to handle cases where the block is missing required fields.

Recommendation

Apply the proposed workaround by implementing the _convert_lc_image_block_to_mistral method to enable native support for image inputs in ChatMistralAI. This will allow for seamless integration with Mistral models and eliminate the need for a custom conversion layer.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

langchain - 💡(How to fix) Fix ChatMistralAI: Add Image Input Support [1 comments, 1 participants]