langchain - 💡(How to fix) Fix convert_to_openai_messages mutates the caller's input message in place [1 pull requests]

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…

Fix Action

Fixed

RAW_BUFFERClick to expand / collapse

convert_to_openai_messages rewrites the caller's own message dict while converting it. For an OpenAI file block with no filename, it does block["file"]["filename"] = "LC_AUTOGENERATED" on the passed-in object (libs/core/langchain_core/messages/utils.py, ~L1778) instead of building a new block. So after calling the function, the original message you passed in is silently modified, a side effect in what looks like a pure converter.

Repro: build a HumanMessage with a file content block that has no filename, call convert_to_openai_messages([msg]), then inspect the original block. Its file.filename is now "LC_AUTOGENERATED". Re-using the same message list (e.g. across providers) carries the mutation forward.

Proposed fix: construct a new block instead of mutating in place. I have a small fix plus a unit test that asserts the caller's input is unchanged, and I'd be happy to open the PR. Could a maintainer assign this to me?

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