Skip to content

fix(core): raise ValueError when explicit tool_outputs length mismatches tool_calls in tool_example_to_messages - #39142

Merged
ccurme (ccurme) merged 3 commits into
langchain-ai:masterfrom
RinZ27:fix/tool-example-messages-mismatch-validation
Aug 11, 2026
Merged

fix(core): raise ValueError when explicit tool_outputs length mismatches tool_calls in tool_example_to_messages#39142
ccurme (ccurme) merged 3 commits into
langchain-ai:masterfrom
RinZ27:fix/tool-example-messages-mismatch-validation

Conversation

@RinZ27

@RinZ27 Rin (RinZ27) commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Fixes #39138

When tool_outputs is explicitly provided with a different length than tool_calls, the current zip(..., strict=False) silently produces a malformed message history — tool calls missing a paired ToolMessage, or extra outputs quietly discarded. Added a length check that raises a descriptive ValueError before the zip. Behavior when tool_outputs=None (auto-generate placeholders) is unchanged.

Release note

tool_example_to_messages now raises ValueError with a clear message when an explicitly-supplied tool_outputs list length does not match the number of tool_calls. Previously the mismatch was silently swallowed.

Verified by running the two new regression tests locally — both directions (fewer and extra outputs) raise as expected, and the original test_tool_outputs still passes.

@github-actions github-actions Bot added core `langchain-core` package issues & PRs fix For PRs that implement a fix size: XS < 50 LOC labels Jul 30, 2026
@github-actions

This comment has been minimized.

@codspeed-hq

codspeed-hq Bot commented Aug 11, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 15 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing RinZ27:fix/tool-example-messages-mismatch-validation (6309077) with master (f4bc503)2

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on master (119bf69) during the generation of this report, so f4bc503 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@ccurme
ccurme (ccurme) merged commit 61c5678 into langchain-ai:master Aug 11, 2026
96 checks passed
@RinZ27
Rin (RinZ27) deleted the fix/tool-example-messages-mismatch-validation branch August 12, 2026 11:53
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 fix For PRs that implement a fix new-contributor size: XS < 50 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(core): tool_example_to_messages silently truncates mismatched tool outputs

2 participants