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.
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 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.