Repository navigation
Conversation
`{% set quantity = quantity | default(1) %}` exists to default a value the
caller supplies, but the prompt builders asked for no `quantity` at all: the
variable extraction subtracted every name a `{% set %}` binds, so the caller's
12 never reached the template and the default won. An `Agent.run(quantity=12)`
then sent "1 cartons" to the model (deepset-ai#13770).
Subtract a bound name only when the assignment does not read it. Jinja itself
already reports such a name as undeclared - the read happens before the binding
- so what was dropped was the caller's own value; an assignment that reads its
target (`{% set a, b = a or 1, 2 %}`) keeps `a` the same way. A `{% set %}` whose
value does not mention its target stays the template's own, and so does a set
that runs in a branch and is read outside it, which is what the subtraction was
there for.
Contributor
|
@Luckyou-d is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
This branch has not been deployed
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.
Problem
{% set quantity = quantity | default(1) %}exists to default a value the caller supplies, but the prompt builders asked for noquantityat all, so the caller's 12 never reached the template and the default won:Agent.run(quantity=12)sent "1 cartons" to the model._collect_assigned_variablessubtracted every name a{% set %}binds:Jinja itself already reports such a name as undeclared - the read happens before the binding - so
template_variables - assigned_variablesremoved exactly the caller's own value:Change
A bound name is subtracted only when the assignment does not read it:
{% set quantity = quantity | default(1) %}{{ quantity }}quantity{% set a, b = a or 1, 2 %}a{% set q = 12 %}{{ q }}{% set quantity %}x{% endset %}{% if flag %}{% set y = 1 %}{% endif %}{{ y }}flagflagThe last two are what the subtraction was for - a value the template itself provides, and a set that runs in a branch but is read outside it - and they are unchanged. Both
{% set x = ... %}and{% set x %}...{% endset %}are handled.Verification
test/components/builders/test_chat_prompt_builder.py: the self-reading set keepsquantityin the builder's inputs andvariables; the plain set stays the template's own. The first fails onmainand passes here.pytest test/components/builders/ test/components/converters/test_output_adapter.py test/utils/test_jinja2_extensions.py-> 199 passed.ruff checkandruff format --checkclean on both files.DEEPSEEK_API_KEYand a live model. The fix is in the variable extraction the Agent's prompt builder runs, and the tests assert the variable list that path produces.Fixes #13770