From e98843404a6dc298fe153eff741ca6104b179bfd Mon Sep 17 00:00:00 2001 From: EvanYao826 <2869018789@qq.com> Date: Tue, 14 Jul 2026 08:56:18 +0800 Subject: [PATCH] fix: skip missing jinja2 variables instead of raising (#38655) When a Jinja2 variable referenced in prompt_config.jinja2_variables is not present in the variable pool (e.g. because a conditional branch was not taken), the LLM node should not fail with VariableNotFoundError. The Jinja2 template already handles optional variables with constructs like {% if variable is defined %}. Instead of calling _get_required_variable (which raises), use variable_pool.get() directly and skip missing variables. --- src/graphon/nodes/llm/node.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/graphon/nodes/llm/node.py b/src/graphon/nodes/llm/node.py index 137c010a..b1839abb 100644 --- a/src/graphon/nodes/llm/node.py +++ b/src/graphon/nodes/llm/node.py @@ -1129,7 +1129,14 @@ def _fetch_jinja_inputs(self, node_data: LLMNodeData) -> dict[str, str]: variables: dict[str, str] = {} for variable_selector in node_data.prompt_config.jinja2_variables or []: - variable = self._get_required_variable(variable_selector) + variable = self.graph_runtime_state.variable_pool.get( + variable_selector.value_selector, + ) + if variable is None: + # Variable not in pool — the Jinja2 template handles this + # gracefully with {% if variable is defined %}, so skip it + # rather than raising VariableNotFoundError. + continue variables[variable_selector.variable] = self._stringify_jinja_variable( variable, )