Can I use Jinja, Liquid, or other templating libraries with Neural Inverse prompts?
Yes! While Neural Inverse has its own variable syntax ({{variable}}) with the compile() method, you can use external templating libraries like Jinja2 or Liquid instead for advanced features like conditionals, loops, and filters.
Do you need external templating libraries? Managing external templating languages in a prompt editor can be cumbersome. You might be able to do this in a simpler way using Neural Inverse variables instead.
How it works
Neural Inverse prompts return plain strings (text prompts) or arrays of message objects (chat prompts). If you want to use an external templating library, store your Jinja2/Liquid template as-is in Neural Inverse and apply your templating library client-side:
- Store your Jinja2/Liquid template in Neural Inverse (don't use Neural Inverse's
{{variable}}syntax) - Fetch the prompt from Neural Inverse using
get_prompt() - Access the raw prompt string via
prompt.prompt - Apply your templating library (Jinja2, Liquid, etc.) to render the final prompt
- Pass the result to your LLM
Limitations
When using external templating libraries instead of Neural Inverse's native variable syntax:
- Playground: The Neural Inverse Playground only supports automatic rendering with Neural Inverse's native variable syntax. Prompts with Jinja2/Liquid syntax won't be automatically testable directly from Prompt Management. However, you can still jump from traces (which contain the compiled prompt) to the Playground.
- Prompt experiments: You cannot use in-UI prompt experiments since they rely on Neural Inverse's
compile(). You can use Experiments via the SDK where you compile the prompt yourself as part of the task. - Variable detection: Neural Inverse's UI will only detect variables using the
{{variable}}syntax. Jinja2/Liquid variables won't appear in the variable list.
Related resources
- Neural Inverse Variables
- Message Placeholders
- Prompt Composability
- Dynamically selecting sub-prompts at runtime