Skip to content

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

@mmabrouk

Description

@mmabrouk

Description

The curly template formatter ({{var}} syntax) raises a TemplateFormatError reporting unreplaced variables when a substituted input value happens to contain {{...}} patterns — even if all template variables were successfully replaced.

Steps to reproduce

from agenta.sdk.types import PromptTemplate

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

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

Expected behavior

The template should substitute {{name}} with the literal string "I am {{name}}", producing "Hello I am {{name}}". The {{name}} in the output is user data, not an unresolved template variable.

Actual behavior

TemplateFormatError is raised because the post-substitution validation (compute_truly_unreplaced) re-scans the rendered output for {{...}} patterns and finds {{name}} in the substituted value, falsely treating it as an unreplaced placeholder.

Root cause

The validation logic in _format_with_template (in both sdk/agenta/sdk/types.py and sdk/agenta/sdk/workflows/handlers.py) works in two phases:

  1. Replace all {{expr}} placeholders with resolved values via apply_replacements
  2. Re-scan the output for any remaining {{...}} patterns and intersect with the original placeholder set (compute_truly_unreplaced)

Step 2 is the problem: it cannot distinguish between {{...}} patterns that were in the original template (genuinely unreplaced) and {{...}} patterns that were injected by substituted values.

Affected code paths

  • PromptTemplate._format_with_template in sdk/agenta/sdk/types.py
  • _format_with_template in sdk/agenta/sdk/workflows/handlers.py

Impact

Any user whose input data contains {{...}} patterns (e.g., template examples, documentation text, code snippets) will get spurious errors when using the curly template format.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions