genkit icon indicating copy to clipboard operation
genkit copied to clipboard

[Go] Dotprompt snake case

Open jannwitt opened this issue 1 year ago • 6 comments

Describe the bug

When passing a Go struct as prompt input to .prompt, fields tagged with snake_case (e.g., org_name, date_range) are silently missing in the rendered prompt. No error is thrown. Using camelCase works.

To Reproduce

  1. example.prompt
---
model: openai/gpt-4.1-mini
input:
  schema:
    items(array):
      org_name: string
      date_range: string
---
{{#each items as |it|}}
Org: {{ it.org_name }}
Range: {{ it.date_range }}
{{/each}}
  1. Go
	prompt := genkit.LookupPrompt(Genkit, promptName)
	if prompt == nil {
		return nil, fmt.Errorf("prompt %s not found", promptName)
	}

	actionOpts, err := prompt.Render(ctx, input)
	if err != nil {
		return nil, fmt.Errorf("error rendering prompt: %w", err)
	}

Log the action options and see that org and date range are missing from the parsed prompt.

  1. Control: Works if using camelCase (template + struct tags): orgName, dateRange.

Expected behavior

Snake_case JSON keys should be available in the template per struct tags; the rendered prompt should include the values or report a validation error if mismatched.

Environment

  • OS: macOS (darwin/arm64)
  • Go: 1.25.1
  • Genkit (Go): 0.7.x

jannwitt avatar Sep 18 '25 07:09 jannwitt

Hey @jannwitt thanks for bringing this up. I'll take a closer look at this.

hugoaguirre avatar Sep 19 '25 21:09 hugoaguirre

Hey @hugoaguirre FYI We encountered another issue with picoschema, where output variable with type enum lead to errors in marshaling the llm responses. We did not dig deeper, everything works well with json schema definitions so we are using those now.

jannwitt avatar Sep 26 '25 08:09 jannwitt

Hi @jannwitt this issue is the next one in my priority list.

I'll keep you posted.

Thanks for the update!

hugoaguirre avatar Sep 26 '25 14:09 hugoaguirre

Hello @jannwitt. I was investigating this issue and found out that the package we are depending on (to render handlebars template) does not support snake case at the moment.

Could it be possible if you change your handlebars template to use camel case in the meantime?

{{#each items as |it|}}
Org: {{ it.orgName }}
Range: {{ it.dateRange }}
{{/each}}

hugoaguirre avatar Sep 30 '25 17:09 hugoaguirre

Thanks @hugoaguirre! Sure thing, we actually just went for JSON Schema definitions instead of Picoschema.

Maybe a little update in the docs could help others to avoid this issue. Silent failure in prompt rendering can bring you into trouble!

jannwitt avatar Oct 22 '25 18:10 jannwitt

Hi @jannwitt, after revisiting the code, I found out my initial analysis was wrong. The fix should be available in the next release.

hugoaguirre avatar Oct 24 '25 18:10 hugoaguirre