核心: mustache 反向部分 `{{^key}}` 位于 `{{#key}}` 列表部分内部,导致渲染失败或引发 `IndexError`
作者: mrutunjay-kinagi创建于 2026年9月15日更新于 2026年9月17日
标签bugcoreexternal
Error:
File ".../langchain_core/prompts/string.py", line 122, in mustache_formatter
return mustache.render(template, kwargs)
File ".../langchain_core/utils/mustache.py", line 525, in render
current_scope = scopes[0]
IndexError: list index out of range
When a section's value is a list, render() gathers the tokens up to the matching {{/key}} and tracks nesting with tags_with_same_key. The counter is incremented only for ("section", key) tokens, but decremented for every ("end", key) token. An inverted section with the same key ({{^items}}...{{/items}}) therefore never increments the counter, yet its closing tag decrements it, so the loop treats the inner {{/items}} as the end of the outer section.
内容来源: langchain-ai/langchain