fix: skip missing jinja2 variables instead of raising LLMNodeError - #214
Open
EvanYao826 wants to merge 1 commit into
Open
fix: skip missing jinja2 variables instead of raising LLMNodeError#214EvanYao826 wants to merge 1 commit into
EvanYao826 wants to merge 1 commit into
Conversation
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.
|
Thanks for the contribution. Before we can review or merge this pull request, please read our CLA and add this exact comment once: I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes langgenius/dify#38655
Summary
When a Jinja2 variable referenced in
prompt_config.jinja2_variablesis not present in the variable pool (e.g. because a conditional branch was not taken),_fetch_jinja_inputsraisesVariableNotFoundErrorand the workflow fails — even though the Jinja2 template already handles optional variables with constructs like{% if variable is defined %}.Root Cause
_fetch_jinja_inputscalls_get_required_variablewhich raisesVariableNotFoundErrorwhen the variable pool returnsNone. The sibling code path_render_jinja2_messagealready handles this correctly by usingvariable_pool.get()and falling back to empty string.Fix
Replace the
_get_required_variablecall in_fetch_jinja_inputswith a directvariable_pool.get()and skip variables that are not in the pool. This aligns with how_render_jinja2_messagealready handles missing variables.Test plan
test_fetch_jinja_inputs_raises_for_missing_variablein dify's test suite updated to expect the new (skip) behavior_fetch_jinja_inputsis called during LLM node_run()— missing variables are simply omitted from the returned dict, which is used for input collection, not the Jinja2 rendering itself