Prompt Template Engine
A Python template engine designed for safe LLM prompt management with built-in validation guards and variable constraints.
Features
- Template Registration: Register named templates with validation guards
- Variable Guards: Enforce min/max length, regex patterns, choices, and custom validators
- Safe Rendering: Automatic variable substitution with error checking
- Random Rendering: Pick random templates for A/B testing or variety
- Template Lookup: Check existence and list all registered templates
Installation
pip install prompt-template-engine
Quick Start
from prompt_template_engine import TemplateEngine, GuardCondition
engine = TemplateEngine()
engine.add_template("hello", "Hello, {name}!", {"name": GuardCondition(name="name", min_length=1)})
result = engine.render("hello", {"name": "World"})
# Returns: "Hello, World!"
API Reference
TemplateEngine
The main engine class for registering and rendering templates.
engine = TemplateEngine()
engine.add_template(name, template_str, guards)
engine.render(name, variables)
engine.has_template(name)
engine.get_template(name)
engine.list_templates()
engine.random()
engine.random_render(variables)
GuardCondition
A dataclass defining validation rules for template variables:
name: Variable namemin_length/max_length: String length constraintsregex: Regular expression patternchoices: Allowed string valuesvalidator: Custom validation function
TemplateTemplate
A reusable template with name, body, and associated guards.
License
MIT
Metadata
Release files for llm-prompt-engine 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| llm_prompt_engine-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Release files / llm_prompt_engine-1.1.0-py3-none-any.whl
| Download URL | llm_prompt_engine-1.1.0-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8d3a5c143bbb10c9a847ca9ecfd1dd03fa97d96e71c7a1d8ef1d869ca28382ed
|
|
BLAKE2b-256 checksum How to use checksums |
88de18aac753a9f39f27b3ee5d07b9245366ac894875e9b040db3d83757c673c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|