-
Notifications
You must be signed in to change notification settings - Fork 611
Description
Bug Description
When loading a .prompt file via LoadPrompt, the template is pre-rendered with an empty DataArgument{}, causing template variables to be replaced with empty values. Subsequent calls to prompt.Execute() with actual input parameters have no effect because the template was already "rendered" at load time.
Root Cause
In the LoadPrompt function in ai/prompt.go:
dpMessages, err := dotprompt.ToMessages(parsedPrompt.Template, &dotprompt.DataArgument{})The LoadPrompt function calls ToMessages with an empty DataArgument{} during prompt loading. This renders the template immediately with empty values instead of preserving the template variables for later substitution.
Steps to Reproduce
- Create a
.promptfile with template variables:
---
model: gemini-1.5-flash
---
Talk about {{topic}} in {{language}}
- Load and execute the prompt with different inputs:
prompt := genkit.LookupPrompt(g, "myPrompt")
// First execution
resp1, _ := prompt.Execute(ctx, ai.WithInput(map[string]any{
"topic": "weather",
"language": "English",
}))
// Second execution with different input
resp2, _ := prompt.Execute(ctx, ai.WithInput(map[string]any{
"topic": "programming",
"language": "Chinese",
}))- Both responses will be about the same topic (or empty), ignoring the input parameters.
Expected Behavior
Template variables should be preserved during LoadPrompt and only substituted when Execute() is called with actual input parameters.
Proposed Fix
Delay template rendering until Execute() is called, or pass the template string to the execution phase instead of pre-rendering with empty values.
Environment
- Go version: 1.23
- genkit version: v1.2.0
Related
This issue is separate from the dotprompt template sharing bug fixed in google/dotprompt#363
Metadata
Metadata
Assignees
Labels
Type
Projects
Status