Skip to content

Comments

fix(sdk): curly template raises false TemplateFormatError when substituted values contain {{variable}} patterns#3797

Open
stakeswky wants to merge 1 commit intoAgenta-AI:mainfrom
stakeswky:fix/3770-curly-template-false-unreplaced
Open

fix(sdk): curly template raises false TemplateFormatError when substituted values contain {{variable}} patterns#3797
stakeswky wants to merge 1 commit intoAgenta-AI:mainfrom
stakeswky:fix/3770-curly-template-false-unreplaced

Conversation

@stakeswky
Copy link

Summary

Fixes #3770

The curly template formatter ({{var}} syntax) raised a false TemplateFormatError when 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 an unresolved set — 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 unresolved set in both affected code paths:

  • sdk/agenta/sdk/types.pyPromptTemplate._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

prompt = PromptTemplate(user_prompt="Hello {{name}}", template_format="curly")

# Before: raises TemplateFormatError("Unreplaced variables in curly template: ['name']")
# After:  returns "Hello I am {{name}}"
result = prompt.format(name="I am {{name}}")

Tests

Added sdk/tests/pytest/unit/test_curly_template.py with 5 test cases:

  • Substituted value containing same placeholder pattern
  • Substituted value containing different placeholder name
  • Multiple variables where one value contains placeholder syntax
  • Genuinely missing variable still raises error
  • Normal case (no placeholder patterns in values)

…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
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Feb 21, 2026
@vercel
Copy link

vercel bot commented Feb 21, 2026

@superman32432432 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

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


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.

@dosubot
Copy link

dosubot bot commented Feb 21, 2026

Related Documentation

Checked 0 published document(s) in 2 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

@dosubot dosubot bot added bug Something isn't working tests labels Feb 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:M This PR changes 30-99 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Curly template formatter raises false TemplateFormatError when substituted values contain {{variable}} patterns

2 participants