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.{ 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
{ 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 withfor.
{ topics: ["AI safety", "Alignment", "Governance"] }:
Comma-separated lists
Useforloop.last to avoid a trailing separator:
Topics: AI, ML, NLP
Loop variables
Inside afor 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 usingassign.
{ name: "alice" }:
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 aPromptCompilationErrorif any variable used in the template is not provided. Use this to catch typos and missing data early.
Further reading
- Get Started with Prompts — Create and use your first prompt
- Prompt Playground — Edit and test prompts interactively
- Data Model — Prompt structure and variable types
- Liquid documentation — Full Liquid language reference