Prompt references (Snippets) allow you to modularize your prompts by referencing other prompts within your project. This feature is particularly useful for:
Managing large projects with reusable prompt components.
Reducing duplication by reusing common sections (e.g., policies, instructions).
Simplifying maintenance by centralizing updates to shared prompts.
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.
You are {{ assistant_name }}, an AI assistant created to help users.Before answering any questions, follow these rules:- Be respectful.- Avoid sharing personal information.- Use appropriate language.
In this example:
The parent prompt references policies.promptl and passes the assistant_name variable.
The 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:
import { render } from 'promptl-ai';import getPrompt from './getPrompt'; // Import your custom resolve functionconst { messages, config } = await render({ prompt: mainPrompt, // Your main PromptL prompt as a string referenceFn: getPrompt, // Provide the resolve function});
Tip: Prompts can be stored in files, a database, or any structured format. Adapt referenceFn to fit your storage solution.
<prompt path="instructions" assistant_name="HelperBot" /><user> What can you do for me?</user>
You are {{ assistant_name }}, an assistant trained to provide technical support.Capabilities:- Debugging code.- Explaining concepts.- Recommending resources.
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.