fix(sdk): curly template raises false TemplateFormatError when substituted values contain {{variable}} patterns#3797
Open
stakeswky wants to merge 1 commit intoAgenta-AI:mainfrom
Conversation
…for curly templates
The curly template formatter raised a false TemplateFormatError when a
substituted value happened to contain {{...}} patterns (e.g. template
examples or code snippets in user input).
Root cause: after substitution, compute_truly_unreplaced() re-scanned
the rendered output for {{...}} patterns and intersected with the
original placeholder set. It could not distinguish between genuinely
unreplaced placeholders and {{...}} patterns injected by substituted
values.
Fix: use the 'unresolved' set already returned by build_replacements()
to detect truly missing variables. This set is computed before
substitution, so it is immune to patterns in substituted values.
Changes:
- types.py: use unresolved from build_replacements instead of
compute_truly_unreplaced
- handlers.py: same fix
- Remove now-unused compute_truly_unreplaced from both files
- Add unit tests covering the false-positive scenario
Fixes Agenta-AI#3770
|
@superman32432432 is attempting to deploy a commit to the agenta projects Team on Vercel. A member of the Team first needs to authorize it. |
|
User 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. |
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.
Summary
Fixes #3770
The curly template formatter (
{{var}}syntax) raised a falseTemplateFormatErrorwhen a substituted value happened to contain{{...}}patterns — even though all template variables were successfully replaced.Root Cause
After substitution,
compute_truly_unreplaced()re-scanned the rendered output for{{...}}patterns and intersected with the original placeholder set. It could not distinguish between genuinely unreplaced placeholders and{{...}}patterns injected by substituted values.Fix
build_replacements()already returns anunresolvedset — the placeholders that could not be resolved against the provided data. This set is computed before substitution, so it is immune to patterns in substituted values.The fix replaces the post-scan approach with the pre-computed
unresolvedset in both affected code paths:sdk/agenta/sdk/types.py—PromptTemplate._format_with_template()sdk/agenta/sdk/workflows/handlers.py—_format_with_template()The now-unused
compute_truly_unreplaced()function is removed from both files.Before / After
Tests
Added
sdk/tests/pytest/unit/test_curly_template.pywith 5 test cases: