Learn how to reference other prompts in PromptL
Prompt references (Snippets) allow you to modularize your prompts by referencing other prompts within your project. This feature is particularly useful for:
To reference another prompt, use the <prompt path="..." />
tag. The path
attribute specifies the relative or absolute path to the referenced prompt.
Referenced prompts are isolated from the parent prompt by default, meaning they don’t inherit variables. However, you can pass variables explicitly using attributes in the <prompt>
tag.
In this example:
policies.promptl
and passes the assistant_name
variable.assistant_name
variable is interpolated in the referenced prompt.Prompt references are not enabled by default. Since PropmtL does not know how your prompts are structured, you must provide a referenceFn
function to define how PromptL should locate and load referenced prompts.
You can structure your prompts in any way you like, as long as your referenceFn
can find and load them. Some examples include:
referenceFn
Create a function that retrieves a prompt based on its path:
To resolve paths relative to the current prompt, you can define a second argument with the current prompt’s full path:
referenceFn
Pass your referenceFn
to the render
function:
Tip: Prompts can be stored in files, a database, or any structured format. Adapt referenceFn
to fit your storage solution.
Prompts can reference other prompts, enabling complex workflows.
prompts/policies.promptl
).If your prompt references aren’t working as expected:
path
in the <prompt>
tag matches the actual file structure.console.log()
in referenceFn
to verify the correct prompt is being loaded.referenceFn
to handle missing or unreadable prompts gracefully:Prompt references enable modular and maintainable prompt structures by allowing you to reuse and manage shared sections across projects. With features like variable passing, nested references, and customizable resolution logic, PromptL makes it easy to handle even the largest and most complex prompt configurations.