Prompt Template Framework — 5-layer Jinja2 template engine for LLM applications
Project description
promptfw — Prompt Template Framework
4-layer Jinja2 template engine for LLM applications.
Installation
pip install promptfw
# With token counting:
pip install promptfw[tiktoken]
Quick Start
from promptfw import PromptStack, PromptTemplate, TemplateLayer
stack = PromptStack()
stack.register(PromptTemplate(
id="story.task.write",
layer=TemplateLayer.TASK,
template="Write a {{ genre }} story about {{ topic }} in {{ words }} words.",
variables=["genre", "topic", "words"],
))
rendered = stack.render("story.task.write", {
"genre": "fantasy",
"topic": "a dragon who learns to code",
"words": 500,
})
# rendered.system → system prompt (SYSTEM + FORMAT layers)
# rendered.user → user prompt (CONTEXT + TASK layers)
4-Layer Stack
SYSTEM → Role & base behaviour (stable, cacheable)
FORMAT → Format-specific rules (stable, cacheable)
CONTEXT → Runtime context (dynamic: characters, world, prior text)
TASK → Concrete task (dynamic: what to write now)
rendered = stack.render_stack(
["system.base", "format.roman", "context.scene", "task.write_scene"],
context={
"role": "professional author",
"style_rules": "Show don't tell",
"characters": "Alice, Bob",
"current_scene": "The forest at night",
"task": "Write scene 3.2",
}
)
Load Templates from YAML
# templates/story/task/write_scene.yaml
# id: story.task.write_scene
# layer: task
# template: |
# Write scene {{ scene_id }}: {{ scene_description }}
# Characters: {{ characters }}
stack = PromptStack.from_directory("templates/")
rendered = stack.render("story.task.write_scene", context)
Wildcard Lookup
# Matches "roman.first_draft.scene_generation"
template = stack.registry.get("roman.*.scene_generation")
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
promptfw-0.5.0.tar.gz
(40.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
promptfw-0.5.0-py3-none-any.whl
(24.4 kB
view details)
File details
Details for the file promptfw-0.5.0.tar.gz.
File metadata
- Download URL: promptfw-0.5.0.tar.gz
- Upload date:
- Size: 40.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4985ff56e95a84f0e94fa5c78af89ecd8b6fac3ee14811fa782f59591cb64900
|
|
| MD5 |
bdc47b86f69fd6ad8f80eaa6e2e37bca
|
|
| BLAKE2b-256 |
cb02ace9a4af849830b7a5ad916336981fcaf3db2d358ae620ea26bbe44cf75d
|
File details
Details for the file promptfw-0.5.0-py3-none-any.whl.
File metadata
- Download URL: promptfw-0.5.0-py3-none-any.whl
- Upload date:
- Size: 24.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e333cd726ea13a5ddd4f11a03ee49de5fcba327675abf58c312492b5686a5e85
|
|
| MD5 |
febef9a23600f75b2eefe90068e78ef0
|
|
| BLAKE2b-256 |
34961e3984ff798039d065b795b9677623cf1025d9d821c185f2e93732b80992
|