Skip to main content
LangWatch prompts use Liquid as their template language, a more powerful alternative to Jinja-style templating with a cleaner syntax. If you’re coming from Jinja2, you’ll find Liquid familiar but with better support for filters, strict compilation modes, and safe rendering out of the box. Liquid gives you variables, conditionals, loops, and filters so you can build dynamic prompts without custom code. Templates are rendered when you call compile() in the Python or TypeScript SDK, or when the platform executes a prompt on your behalf.

Variables

Use double curly braces to insert dynamic values into your prompt.
When compiled with { user_name: "Alice", message_count: 3 }, this produces:

Accessing nested properties

Dot notation lets you reach into objects:

Available variables

The variables available depend on how you invoke the prompt:

Conditionals

Control which parts of a prompt appear based on runtime values.

if, elsif, else

Compiled with { tone: "formal", user_name: "Dr. Smith" }:

unless

unless is the inverse of if — the block renders when the condition is false.

Operators

Loops

Iterate over arrays with for.
Compiled with { topics: ["AI safety", "Alignment", "Governance"] }:

Comma-separated lists

Use forloop.last to avoid a trailing separator:
Produces: Topics: AI, ML, NLP

Loop variables

Inside a for block, these variables are available:

Nested loops and conditionals

Loops and conditionals compose freely:

Filters

Filters transform a value. Chain them with the pipe character (|).

String filters

Array filters

Other filters

Truncate behavior differs between SDKs. In the TypeScript SDK (LiquidJS), truncate: N outputs N characters of content then appends "...". In the Python SDK (python-liquid), truncate: N means N total characters including the "..." suffix. Keep this in mind if you rely on exact output length.

Assignment

Create local variables within the template using assign.
Compiled with { name: "alice" }:
Assigned variables are local to the template — they do not need to be passed in and will not appear as required input variables.

Comments

Use comment tags for notes that should not appear in the rendered output.

Practical examples

Conditional system prompt

Adapt the system message based on user input:

Few-shot examples from a list

Build few-shot examples dynamically:

Context-aware RAG prompt

Include retrieved context only when it exists:

Multi-language greeting

Strict vs. lenient compilation

The SDKs offer two compilation modes:
  • compile() — Lenient. Undefined variables resolve to empty strings and missing conditions evaluate to false. Useful for optional fields.
  • compileStrict() (TypeScript), compile_strict() (Python) — Strict. Throws a PromptCompilationError if any variable used in the template is not provided. Use this to catch typos and missing data early.

Further reading