Skip to main content

Prompt Template Framework — 4-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.1.0.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

promptfw-0.1.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file promptfw-0.1.0.tar.gz.

File metadata

  • Download URL: promptfw-0.1.0.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for promptfw-0.1.0.tar.gz
Algorithm Hash digest
SHA256 273e7d553a72af519a35f066e7835b1431637c9f8fe7d180f55b18a7d2b7b2af
MD5 088d95e561f3c3310fc74026a8b498e8
BLAKE2b-256 a4d61fa4cdb11b1b9ecfae81b992eb23534bcc4829e4f4da0cc7473ba72bb70e

See more details on using hashes here.

File details

Details for the file promptfw-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: promptfw-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for promptfw-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8abbec5d836ba04fa9570191c530e68b70bf20b4d55c7d408dd09ff58d5d9a49
MD5 98fddadbb28b1fd159f111b35ca6d0a6
BLAKE2b-256 83892a455b1aa41c77f96d20ca6de12280ea68cf4c5e3bc8addd95d2e1ecc3f9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page