Skip to content

fix(prompts): substitute template variables with falsy values (0, false, "")#5714

Open
devteamaegis wants to merge 1 commit into
Helicone:mainfrom
devteamaegis:fix/prompt-template-falsy-substitution
Open

fix(prompts): substitute template variables with falsy values (0, false, "")#5714
devteamaegis wants to merge 1 commit into
Helicone:mainfrom
devteamaegis:fix/prompt-template-falsy-substitution

Conversation

@devteamaegis

Copy link
Copy Markdown

What's broken

HeliconeTemplateManager.substituteVariables left the raw {{hc:NAME:type}} placeholder in the rendered prompt whenever an input value was falsy (0, false, or ""), so those literals were sent to the LLM instead of the real value.

input {count: 0}     => "You have {{hc:count:number}} new messages"   (want "You have 0 new messages")
input {flag: false}  => "Enabled: {{hc:flag:boolean}}"                (want "Enabled: false")

Why it happens

The replacement callback used value ? String(value) : match, which treats 0/false/"" as "missing". The JSON substitution path (performRegexReplacement) already guards with value !== undefined && value !== null; the string path didn't.

Fix

One line in packages/prompts/templates.ts — switch the truthiness check to an explicit undefined/null check, matching the JSON path. Missing variables (genuinely undefined) still leave the placeholder untouched.

Test

Added packages/__tests__/prompts/templates.test.ts. Fails before the change (placeholder leaks for count: 0), passes after. Truthy values and missing-variable behavior unchanged.

@vercel

vercel Bot commented Jul 7, 2026

Copy link
Copy Markdown

@devteamaegis is attempting to deploy a commit to the Helicone Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

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