Safe LLM prompt templating with validation guards
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
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
File details
Details for the file llm_prompt_engine-1.1.0-py3-none-any.whl.
File metadata
- Download URL: llm_prompt_engine-1.1.0-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d3a5c143bbb10c9a847ca9ecfd1dd03fa97d96e71c7a1d8ef1d869ca28382ed
|
|
| MD5 |
8540c9ef46d6dfb3861718a64ca85256
|
|
| BLAKE2b-256 |
88de18aac753a9f39f27b3ee5d07b9245366ac894875e9b040db3d83757c673c
|