Skip to content

fix(components): keep template inputs reassigned by self-referencing {% set %} - #13756

Open
Sun-Wukhan wants to merge 1 commit into
deepset-ai:mainfrom
Sun-Wukhan:fix/set-self-reference-template-inputs
Open

Sun-Wukhan wants to merge 1 commit into
deepset-ai:mainfrom
Sun-Wukhan:fix/set-self-reference-template-inputs

Conversation

@Sun-Wukhan

Copy link
Copy Markdown

Why

PromptBuilder, ChatPromptBuilder and OutputAdapter compute their inputs as template_variables - assigned_variables. When a template reassigns a variable from itself, for example {% set query = query | trim %} or {% set documents = documents[:3] %}, the variable is read from the caller before it is set, but _collect_assigned_variables still counts it as purely template-internal, so the input socket is dropped and pipelines fail with ValueError: Input 'query' not found.

Fixes #13753

How

In _collect_assigned_variables (haystack/utils/jinja2_extensions.py), a {% set %} target is no longer treated as assigned when its own assignment reads it: the names loaded by the assignment's value (or block body) are collected, and any target among them stays a template input. Purely internal assignments, including ones that read other variables, are unchanged.

Tests

  • New regression tests in test_prompt_builder.py, test_chat_prompt_builder.py and test_output_adapter.py covering the self-referencing patterns from the issue, plus direct tests of _extract_template_variables_and_assignments in test/utils/test_jinja2_extensions.py.
  • The four test files pass (165 tests). Without the fix, the five new self-referencing tests fail and the rest pass.

@Sun-Wukhan
Sun-Wukhan requested a review from a team as a code owner November 14, 2026 23:45
@Sun-Wukhan
Sun-Wukhan requested review from bogdankostic and removed request for a team November 14, 2026 23:45
@vercel

vercel Bot commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

@Sun-Wukhan is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant

CLAassistant commented Nov 14, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@HaystackBot

Copy link
Copy Markdown
Contributor

Hi @Sun-Wukhan, thanks a lot for your contribution! 🙏

We noticed that the Contributor License Agreement (CLA) check (license/cla) hasn't passed yet, so we've temporarily moved this PR to draft and paused the review assignment.

To get your PR reviewed, please sign the CLA via the link in the license/cla check below (or in the CLA bot comment). As soon as the check turns green, this PR will automatically be marked ready for review again and a reviewer will be re-assigned.

@HaystackBot
HaystackBot removed the request for review from bogdankostic November 15, 2026 00:55
@HaystackBot HaystackBot added the cla-pending PR is in draft until the contributor signs the CLA label Nov 15, 2026
@HaystackBot
HaystackBot marked this pull request as draft November 15, 2026 00:55
@Sun-Wukhan

Copy link
Copy Markdown
Author

Hi @Sun-Wukhan, thanks a lot for your contribution! 🙏

We noticed that the Contributor License Agreement (CLA) check (license/cla) hasn't passed yet, so we've temporarily moved this PR to draft and paused the review assignment.

To get your PR reviewed, please sign the CLA via the link in the license/cla check below (or in the CLA bot comment). As soon as the check turns green, this PR will automatically be marked ready for review again and a reviewer will be re-assigned.

My bad! Signing the CLA now! Appreciate you for taking the time to look at this btw.

@github-actions github-actions Bot added the P2 Medium priority, add to the next sprint if no P1 available label Nov 16, 2026
@HaystackBot

Copy link
Copy Markdown
Contributor

Hi @Sun-Wukhan, this PR is still waiting for the Contributor License Agreement (CLA) to be signed. Please note that if the CLA isn't signed within the next 24 hours, this PR will be automatically closed. Signing only takes a minute via the link in the license/cla check, and the PR will then automatically be marked ready for review.

@HaystackBot
HaystackBot marked this pull request as ready for review November 20, 2026 12:42
@HaystackBot HaystackBot removed the cla-pending PR is in draft until the contributor signs the CLA label Nov 20, 2026
@HaystackBot

Copy link
Copy Markdown
Contributor

Thanks for signing the CLA, @Sun-Wukhan! 🎉 This PR is now ready for review again and the reviewer has been re-assigned.

@Sun-Wukhan

Copy link
Copy Markdown
Author

Sorry team, signed the CLA just now.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Medium priority, add to the next sprint if no P1 available topic:tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PromptBuilder, ChatPromptBuilder and OutputAdapter drop an input that the template reassigns with {% set x = x ... %}

3 participants