Skip to main content

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 name
  • min_length / max_length: String length constraints
  • regex: Regular expression pattern
  • choices: Allowed string values
  • validator: Custom validation function

TemplateTemplate

A reusable template with name, body, and associated guards.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

llm_prompt_engine-1.1.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file llm_prompt_engine-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for llm_prompt_engine-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8d3a5c143bbb10c9a847ca9ecfd1dd03fa97d96e71c7a1d8ef1d869ca28382ed
MD5 8540c9ef46d6dfb3861718a64ca85256
BLAKE2b-256 88de18aac753a9f39f27b3ee5d07b9245366ac894875e9b040db3d83757c673c

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