You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bug description
When passing a Map into a PromptTemplate as a param to iterate over, validation fails due to an erroneously detected missing input variable.
The same template and params work correctly when using StringTemplate directly.
Environment
Spring AI 1.0.0-SNAPSHOT
Java 22
Steps to reproduce
The following unit tests indicate the issue, with the first failing using PromptTemplate, and the second succeeding using StringTemplate directly.
The template should render and return the simple iteration over the map keys and values. To note, the same error occurs with List iteration (as per #631) if the same variable is used twice in the loop block.
Notes
I think it would be worth making validation optional, as otherwise it may end up a game of whack-a-mole trying to handle all the cases where StringTemplate is used for more than variable substitution.
For instance, we have a more-bespoke RAG-like use-case that would benefit from a complex prompt with conditionals and iterations.
Similarly, would be great to get #355 in as { and } are used by StringTemplate itself to indicate an anonymous template block for iteration, which makes the templates quite confusing to develop. (Minor point, but coming from Python, I find being able to look at StringTemplate docs and having working IDE syntax checking more useful that the passing similarly with Python templates that using curly braces brings).
Thanks for the great library!
The text was updated successfully, but these errors were encountered:
Follow-up from #631
Bug description
When passing a
Map
into aPromptTemplate
as aparam
to iterate over, validation fails due to an erroneously detected missing input variable.The same template and params work correctly when using
StringTemplate
directly.Environment
Steps to reproduce
The following unit tests indicate the issue, with the first failing using
PromptTemplate
, and the second succeeding usingStringTemplate
directly.The error from the first test is,
Expected behavior
The template should render and return the simple iteration over the map keys and values. To note, the same error occurs with List iteration (as per #631) if the same variable is used twice in the loop block.
Notes
I think it would be worth making validation optional, as otherwise it may end up a game of whack-a-mole trying to handle all the cases where
StringTemplate
is used for more than variable substitution.For instance, we have a more-bespoke RAG-like use-case that would benefit from a complex prompt with conditionals and iterations.
Similarly, would be great to get #355 in as
{
and}
are used byStringTemplate
itself to indicate an anonymous template block for iteration, which makes the templates quite confusing to develop. (Minor point, but coming from Python, I find being able to look atStringTemplate
docs and having working IDE syntax checking more useful that the passing similarly with Python templates that using curly braces brings).Thanks for the great library!
The text was updated successfully, but these errors were encountered: