General
Nested Substitution Recipe
Recipe for nested substitution using Handlebars skip and substitute helpers. Useful for multi-stage rendering, preserving placeholders, and controlled dynamic content generation.
User Engagement
Example User Requests :
- How can I implement nested substitution in my Stubber agent?
- I want my bot to interpolate runtime data into it's system prompt on the
_createaction, how can I do that?
Clarification Questions
- Where in
template.datais your system prompt stored? - What is the runtime data (
stubpost.data) you want to interpolate into your system prompt?
Example Answers
- My system prompt is stored in
template.data.prompts.system - The runtime data I want to interpolate is the user's name, which is stored in
stubpost.data.customer_name
Implementation Plan
Implementation Steps:
- Add
stubpost.data.customer_nameto the prompt in question, inside the skip helper, like so:
This will ensure that
{{stubpost.data.customer_name}}is not substituted during the initial template rendering phase, allowing it to be available for substitution during the_createaction.Inside a task in the
_createaction, use the substitute helper to perform the nested substitution ontemplate.data.prompt.system, like so:
- The final system prompt sent to the model will have the
stubpost.data.customer_namevalue substituted in, allowing for dynamic and personalized interactions based on runtime data.
Where John is the value of stubpost.data.customer_name at runtime.