Skip to content

Fix/template substitution logic#3709

Merged
mmabrouk merged 12 commits intoAgenta-AI:release/v0.87.1from
Vishesh-Paliwal:fix/template-substitution-logic
Feb 26, 2026
Merged

Fix/template substitution logic#3709
mmabrouk merged 12 commits intoAgenta-AI:release/v0.87.1from
Vishesh-Paliwal:fix/template-substitution-logic

Conversation

@Vishesh-Paliwal
Copy link
Copy Markdown
Contributor

@Vishesh-Paliwal Vishesh-Paliwal commented Feb 10, 2026

This PR aims to fix issue #3700

Problem :

The Agenta SDK's curly template formatter ({{var}} syntax) raises TemplateFormatError when a substituted input value contains the same {{variable_name}} patterns used in the template itself. The SDK performs a post-substitution validation that detects these patterns in the final text and treats them as unreplaced variables.

Proposed Solution :

Instead of post-substitution validation , I am proposing we keep two sets

  • replacements dict , which we already have
  • successfully replaced set containing keys which we were able to replace successfully

hence we will in first pass over the prompt , keep checking if our matched regex is in replacement dict , then we will add that key to successfully replaced set . Therefore true failures or truely_unreplaced keys = original_placeholders - successfully_replaced_placeholders .

Attaching the images for reference :

Old Flow :
Screenshot 2026-02-11 at 3 27 33 AM

New Flow :
Screenshot 2026-02-11 at 3 29 43 AM


Open with Devin

@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 10, 2026

Someone is attempting to deploy a commit to the agenta projects Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Feb 10, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ Vishesh-Paliwal
❌ Vishesh Paliwal


Vishesh Paliwal seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@Vishesh-Paliwal Vishesh-Paliwal marked this pull request as ready for review February 11, 2026 09:34
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Feb 11, 2026
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 4 additional findings.

Open in Devin Review

@dosubot dosubot Bot added the SDK label Feb 11, 2026
@Vishesh-Paliwal
Copy link
Copy Markdown
Contributor Author

Hey @mmabrouk , any updates on this PR

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 4 additional findings.

Open in Devin Review

Copy link
Copy Markdown
Member

@mmabrouk mmabrouk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Vishesh-Paliwal for your PR!

I have reviewed the fix. It is correct, tracking replacements during substitution instead of re-scanning the output is the right approach.

Can you please add these two cleanup items before merging:

  1. Remove dead code
    apply_replacements and compute_truly_unreplaced are no longer called anywhere after this PR. Please remove them from both files:
types.py:640-653
handlers.py:246-259
  1. Deduplicate _PLACEHOLDER_RE
    The same regex re.compile(r"{{\s*(.?)\s}}") is now defined in three places:
helpers.py:50
types.py:605
handlers.py:211

Since helpers.py now owns the replacement logic, it should also be the single source for this regex. types.py and handlers.py should import it from helpers.py (their extract_placeholders functions already use a local copy). Ideally extract_placeholders itself would also move to helpers.py to consolidate fully, but at minimum the regex should not be defined three times, if the pattern ever needs to change, having three copies is a bug waiting to happen.

@mmabrouk
Copy link
Copy Markdown
Member

@Vishesh-Paliwal Please also sign the CLA with this github account. I think you signed it with the other

@mmabrouk
Copy link
Copy Markdown
Member

I've discovered another issue that was already there before. Maybe you want to tackle it next @Vishesh-Paliwal in a separate (stacked) PR

Vishesh Paliwal added 3 commits February 18, 2026 11:51
Merge branch 'main' of github.com:Vishesh-Paliwal/agenta into fix/template-substitution-logic
Merge branch 'fix/template-substitution-logic' of github.com:Vishesh-Paliwal/agenta into fix/template-substitution-logic
@Vishesh-Paliwal
Copy link
Copy Markdown
Contributor Author

thanks @mmabrouk , have removed the unused fxns and redundant declarations ,
also the other issue should also be solved without any extra PR after merging this PR already I think

Screenshot 2026-02-18 at 12 13 32 PM

@Vishesh-Paliwal
Copy link
Copy Markdown
Contributor Author

Also , regarding this cla thing I am also not sure actually why it is happening ,I only have one github account with which i signed 😅 and commiting with the same .

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Feb 22, 2026
@mmabrouk mmabrouk changed the base branch from main to release/v0.87.1 February 26, 2026 17:02
@mmabrouk mmabrouk merged commit 51af6f5 into Agenta-AI:release/v0.87.1 Feb 26, 2026
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer SDK size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants