Skip to content

core[patch]: preserve MIME type on base64 file blocks in openai translator#36937

Closed
Anmol Jaiswal (anmolg1997) wants to merge 1 commit intolangchain-ai:masterfrom
anmolg1997:fix/file-block-mime-type
Closed

core[patch]: preserve MIME type on base64 file blocks in openai translator#36937
Anmol Jaiswal (anmolg1997) wants to merge 1 commit intolangchain-ai:masterfrom
anmolg1997:fix/file-block-mime-type

Conversation

@anmolg1997
Copy link
Copy Markdown

@anmolg1997 Anmol Jaiswal (anmolg1997) commented Apr 22, 2026

Fixes #36939.

The file branch of _convert_openai_format_to_data_block hard-codes mime_type="application/pdf", while the image branch right above it uses parsed["mime_type"] from the data URI. So a CSV sent via the OpenAI file block shape comes out with mime_type="application/pdf" in the v1 content block.

One-line change to read it off the parsed data URI, same as the image branch. _parse_data_uri returns None when the mime_type is missing, so parsed["mime_type"] is always set inside this branch.

Test added with a CSV and a text/plain data URI. Existing tests still pass since they use data:application/pdf;....

…lator

`_convert_openai_format_to_data_block` in the `openai` block translator
hard-codes `mime_type="application/pdf"` for every base64 file block.
Any non-PDF file (e.g. `data:text/csv;base64,...`, `data:text/plain`,
spreadsheets, office docs) is silently relabeled as `application/pdf` on
the way into v1 content blocks.

The sibling `image_url` branch right above it already reads
`parsed["mime_type"]` off the data URI. This patch does the same for the
file branch, so both base64 paths are consistent and the incoming MIME
type round-trips correctly. `_parse_data_uri` guarantees `mime_type` is
non-empty whenever `parsed` is truthy, so no extra None check is needed.

Adds a regression test covering CSV and plain-text base64 file blocks.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 22, 2026

This PR has been automatically closed because you are not assigned to the linked issue.

External contributors must be assigned to an issue before opening a PR for it. Please:

  1. Comment on the linked issue to request assignment from a maintainer
  2. Once assigned, your PR will be reopened automatically

Maintainers: reopen this PR or remove the missing-issue-link label to bypass this check.

@github-actions
Copy link
Copy Markdown

You have been assigned to #36939, but this PR could not be reopened because the head branch has been deleted. Please open a new PR referencing the issue.

1 similar comment
@github-actions
Copy link
Copy Markdown

You have been assigned to #36939, but this PR could not be reopened because the head branch has been deleted. Please open a new PR referencing the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core `langchain-core` package issues & PRs external missing-issue-link new-contributor size: XS < 50 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

core: _convert_openai_format_to_data_block hard-codes mime_type on base64 file blocks

1 participant