FAQ

Can I use Jinja, Liquid, or other templating libraries with Langfuse prompts?

Yes! While Langfuse 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 Langfuse variables instead.

How it works

Langfuse 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 Langfuse and apply your templating library client-side:

  1. Store your Jinja2/Liquid template in Langfuse (don’t use Langfuse’s {{variable}} syntax)
  2. Fetch the prompt from Langfuse using get_prompt()
  3. Access the raw prompt string via prompt.prompt
  4. Apply your templating library (Jinja2, Liquid, etc.) to render the final prompt
  5. Pass the result to your LLM

Limitations

When using external templating libraries instead of Langfuse’s native variable syntax:

  • Playground: The Langfuse Playground only supports automatic rendering with Langfuse’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 Langfuse’s compile(). You can use Experiments via the SDK where you compile the prompt yourself as part of the task.
  • Variable detection: Langfuse’s UI will only detect variables using the {{variable}} syntax. Jinja2/Liquid variables won’t appear in the variable list.
Was this page helpful?