promptml
Type-safe LLM prompt templates for Rust, with compile-time variable checking.
Why
Prompt templates in most LLM libraries are plain strings. Forget a variable
and you get a broken prompt at runtime — or worse, silently wrong output.
promptml catches missing variables at compile time using a proc macro,
and at runtime with clear, descriptive error messages.
Install
[]
= "0.1"
Usage
Compile-time safety with prompt!
use prompt;
let t = prompt!;
// Compiles and runs fine
let out = t.render
.set
.set
.build?;
// Fails at compile time — missing variable caught before you ship
let bad = t.render
.set
.build;
# Ok::
Runtime templates
use PromptTemplate;
let t = new?;
let out = t.render
.set
.set
.build?;
# Ok::
Optional blocks
let t = prompt!;
Few-shot examples
use ;
use HashMap;
let t = prompt!;
let mut e1 = new;
e1.insert;
e1.insert;
let out = t.render
.set
.examples
.build?;
# Ok::
Chat message format
use chat_prompt;
let messages = chat_prompt!
.render
.set
.set
.to_messages?;
# Ok::
Load templates from a TOML file
use PromptTemplate;
let t = from_file?;
# Ok::
# prompts/summarise.toml
[]
= "summarise"
[]
= "You are a concise technical writer."
= "Summarise the following {doc_type} in {max_bullets} bullet points.\n\n{content}"
License
MIT — see LICENSE-MIT