Fix/template substitution logic#3709
Conversation
|
Someone is attempting to deploy a commit to the agenta projects Team on Vercel. A member of the Team first needs to authorize it. |
|
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. |
|
Hey @mmabrouk , any updates on this PR |
mmabrouk
left a comment
There was a problem hiding this comment.
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:
- Remove dead code
apply_replacementsandcompute_truly_unreplacedare no longer called anywhere after this PR. Please remove them from both files:
types.py:640-653
handlers.py:246-259
- 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.
|
@Vishesh-Paliwal Please also sign the CLA with this github account. I think you signed it with the other |
|
I've discovered another issue that was already there before. Maybe you want to tackle it next @Vishesh-Paliwal in a separate (stacked) PR |
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
|
thanks @mmabrouk , have removed the unused fxns and redundant declarations ,
|
|
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 . |

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
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 :

New Flow :
