bug(core): Mustache inverted section variables are missing from inputVariables, so PipelinePromptTemplate renders them empty
Description
For mustache templates, variables inside an inverted section ({{^key}}...{{/key}}) are not added to inputVariables. mustacheTemplateToNodes in libs/langchain-core/src/prompts/template.ts only recurses into # sections, so the children of ^ sections are skipped.
This matters wherever inputVariables is used to pick values. PipelinePromptTemplate.extractRequiredInputValues only forwards the listed variables, so the value never reaches the inner prompt and renders as an empty string.
Example code
import { PromptTemplate, PipelinePromptTemplate } from "@langchain/core/prompts";
const inner = PromptTemplate.fromTemplate(
"{{^items}}No items for {{name}}.{{/items}}",
{ templateFormat: "mustache" }
);
console.log(inner.inputVariables); // ["items"]
const pipeline = new PipelinePromptTemplate({
pipelinePrompts: [{ name: "summary", prompt: inner }],
finalPrompt: PromptTemplate.fromTemplate("{{summary}}", { templateFormat: "mustache" }),
});
console.log(await pipeline.format({ items: [], name: "Bob" })); // "No items for ."Expected
inputVariables is ["items", "name"] and the pipeline renders No items for Bob.
Actual
inputVariables is ["items"] and the pipeline renders No items for .
Cause
Mustache renders an inverted section only when its key is falsy, and it reads the variables inside from the outer context, so they are real top-level inputs. The # branch already recurses into section children (added in #8580), but ^ does not.
System info
@langchain/core on main (17b6bba), Node 22
Source: langchain-ai/langchainjs