Skip to content

Deduplicate variable names in Template MissingVariables error - #1539

Open
lntutor wants to merge 1 commit into
simonw:mainfrom
lntutor:fix/dedupe-missing-template-vars
Open

Deduplicate variable names in Template MissingVariables error#1539
lntutor wants to merge 1 commit into
simonw:mainfrom
lntutor:fix/dedupe-missing-template-vars

Conversation

@lntutor

@lntutor lntutor commented Jul 19, 2026

Copy link
Copy Markdown

When a template reuses the same variable and it isn't supplied, the error currently lists it once per textual occurrence:

Template(name="t", prompt="Dear $name, from $name").evaluate("input", {})
# llm.templates.MissingVariables: Missing variables: name, name

A variable is either missing or not, so reporting it N times is incorrect. Template.interpolate builds missing = [p for p in vars if p not in params] without de-duplicating.

This de-duplicates the missing list while preserving first-seen order, so "Dear $name, from $name" reports Missing variables: name and "$a $b $a" reports Missing variables: a, b. The existing distinct-variable message (Missing variables: one, two) is unchanged.

Adds two parametrized cases to tests/test_templates.py::test_template_evaluate. Full tests/test_templates.py suite passes (47).

When a template reuses the same variable (e.g. "Dear $name, from $name")
and it isn't supplied, evaluate() reported it once per textual occurrence
("Missing variables: name, name"). Deduplicate the missing list while
preserving first-seen order so each name is reported once.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N6RtoHuxrDqTUo9Mw9h4Cv
@lntutor
lntutor force-pushed the fix/dedupe-missing-template-vars branch from d551ace to e9a1f1c Compare July 27, 2026 15:05
@lntutor

lntutor commented Aug 1, 2026

Copy link
Copy Markdown
Author

Current head e9a1f1cbe2a804b2ba200ad2c881f89dd13052f9 is mergeable, the Read the Docs preview is green, and there are no unresolved review threads on the current PR state. This looks ready for maintainer review when convenient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant