Go template is not working in grafana alert's annotations

I have configured a Grafana (v11.1.0) alert where alert should fire if the max value of any of the three parameters, say A, B and C is greater than 0. I have defined the custom message in the alert annotation section. The alerts are firing, however, the template is not evaluated. Entire template is printed as is. Below are more details.

Reduce statements are defined each parameter, say, D, E, F. All of them has similar criteria. Below is sample screenshot for one of them.

image

Annotation section:

Summary:

{{if or (gt $values.D.value 0) (gt $values.E.value 0)-}}
  Message1
{{else -}}
  Message2
{{end }}

Output in the alert:

{{if or (gt $values.D.value 0) (gt $values.E.value 0)-}}
  Message1
{{else -}}
  Message2
{{end }}

Description:

{{if (gt $values.D.value 0) -}}
  Message3
{{else if (gt $values.E.value 0) -}}
  Message4
{{else -}}
  Message5.
{{end }}

Output in the alert:

{{if (gt $values.D.value 0) -}}
  Message3
{{else if (gt $values.E.value 0) -}}
  Message4
{{else -}}
  Message5.
{{end }}

I have cross checked with documentation and online examples and observed that the templates I have defined looks ok. However I am not sure why the are not working. This is the first Alert I am working on. So, don’t have much expertise on this. Please let me know if I am missing something.

Hello,

I’ve had more or less the same issue while trying to use the annotations the same way you did. I noticed that the displayed annotation is the plain text of the template you are trying to configure, when the template is not properly done, but you never get information about why it doesn’t give you your “Message1” or “Message2” under your conditions.
What helped me to use the template is that even though your query returns a value of type integer and you see from the UI that it doesn’t have decimal, Grafana internal processing converts these values to floats during the alert evaluation pipeline.
I had then to use values with decimals like 0.0 or 1.0 to compare with my values. Also I noticed you’re using your values like “$values.E.value”, I used something like “$values.E.Value” which worked for me.
Hoping it helped you.
Alex.F