Re:Java string interpolation feature has been cancelled
by elric on Friday June 21, 2024 @01:23PM
(#40751707)
Longer strings with more tokens are exactly where real templating engines with proper parsing/quoting/sanitizing would shine, instead of injection-prone interpolation.
Re:Java string interpolation feature has been cancelled
by CharlieDigital on Friday June 21, 2024 @02:14PM
(#40752188)
In the case of prompting, a lot of the work is actually in shaping the context -- typically using data you already have from somewhere else. The prompt really doesn't care about the quoting and parsing would have been done beforehand when the content was acquired.
With respect to mitigating injections, when dealing with user entered prompt fragments, I don't think there's any templating engine that would be able to address this because it's not a standard format like SQL or JavaScript. Typically, we run the input prompt through another prompt first to test for validity of the prompt in the context of the flow and reject the prompt fragment if it's not valid for the context.
Not something a template engine is going to solve.
C# can also use `String.Format("My template: {0}", name)`, but `$"My template: {name}"` is much nicer, IMO.
The longer the string and the higher the number of tokens, the more it benefits. I find this particularly true with working with LLM prompts, for example.