Skip to content

fix(core): accept non-dict Mapping values in mustache templates - #39680

Merged
ccurme (ccurme) merged 1 commit into
langchain-ai:masterfrom
Haaaarry:Haaaarry/core/mustache-mapping
Aug 18, 2026
Merged

fix(core): accept non-dict Mapping values in mustache templates#39680
ccurme (ccurme) merged 1 commit into
langchain-ai:masterfrom
Haaaarry:Haaaarry/core/mustache-mapping

Conversation

@Haaaarry

Copy link
Copy Markdown
Contributor

Fixes #39678


Mustache templates document their input as a Mapping[str, Any], but only plain dict values actually resolved. Any other Mapping — a ChainMap, UserDict, MappingProxyType, or os.environ — silently rendered as an empty string, so users passing a valid Mapping saw variables disappear with no error and no way to tell a missing key from an unsupported type.

The nested-value lookup now dispatches on the abstract Mapping ABC instead of the concrete dict, so every Mapping resolves through __getitem__ exactly as the API promises. The else branch that rejects traversal into arbitrary objects is unchanged, so the earlier template-injection hardening still applies.

Added a unit test covering ChainMap, UserDict, and MappingProxyType values.

Release note

Mustache prompt templates now resolve variables from any Mapping value (such as ChainMap, UserDict, or os.environ), not only dict.


This contribution was prepared with AI assistance.

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

This comment has been minimized.

@ccurme
ccurme (ccurme) merged commit 9c21d84 into langchain-ai:master Aug 18, 2026
104 of 189 checks passed
@codspeed-hq

codspeed-hq Bot commented Aug 18, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 15 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing Haaaarry:Haaaarry/core/mustache-mapping (01a3729) with master (300eb71)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 (9a58107) during the generation of this report, so 300eb71 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

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

2 participants