API Reference
Exhaustive technical specification for the prompt-template-manager. Built for deterministic integration into agentic workflows and complex LLM pipelines.
Evaluation Lifecycle
Execution is split into three distinct phases. Understanding exactly when resolution occurs is critical for managing environment secrets versus runtime data.
Load Time
PromptManager()
- YAML parsing & validation
-
{env:VAR}resolution - Collision detection
Access Time
manager.get()
- Fallback logic execution
- Model-tag resolution
- Cache lookup & instantiation
Format Time
prompt.format()
- Recursive
{include} - Variable
{var}injection - Type coercion (Dict to JSON)
YAML Schema Specification
Reserved Keys
Resolution Logic
Resolving manager.get(name, model=M, version=V) follows this sequence:
Explicit Version
version="v2" | version=2
Model Match
model="gpt-4o"
Default Fallback
content[_default]
1# 1. Simple mapping2simple_task: "Write a summary of {text}"34# 2. Managed versions5complex_task:6 _default: v27 _meta:8 author: "Dave"9 max_tokens: "4000"1011 v1: "Refactor: {code}"12 v2: "Refactor {code} concisely."1314 # 3. Chat format15 claude-3-opus:16 - role: system17 content: "You are an expert engineer."18 - role: user19 content: "Refactor: {code}"
Directives & Syntax
Recursive IncludesFormat Time
Compose templates using {include prompt_name}. Resolution is recursive and detects circular dependencies.
Incompatibility Rule
Includes are only supported for string-format prompts. You cannot include a chat-format prompt into another template.
Environment InjectionLoad Time
Inject environment variables using {env:VAR_NAME}. Resolved exactly once during initialization.
1system_prompt: "Active Env: {env:APP_ENV}" # Resolved at startup
Regex Specification
PromptManager
__init__
Initializes the manager and recursively loads prompt sources from disk.
File path to .yaml or folder containing .yaml and .txt files.
Variables bound to every Prompt object returned by this manager.
Enables background thread to monitor file changes and trigger auto-reload.
1from prompt_template_manager import PromptManager23manager = PromptManager(4 source_path="./prompts/",5 context={"user": "Dave"},6 watch=True7)
get()
Returns a resolved Prompt instance with automatic resolution.
Unique prompt key from YAML.
Exact version key. Integers are prefixed with 'v'.
Attempts model-specific resolution, fallback to _default.
1prompt = manager.get("auth_check", model="gpt-4o")
list()
Returns the complete library catalog.
Essential for building UI-based prompt explorers or static analysis tools.
1[{2 "name": "greet",3 "versions": ["v1", "gpt-4"],4 "variables": ["user"],5 "meta": {"author": "Marketing"}6}]
reload()
Clears all caches and re-parses the source files.
No arguments. Re-scans source_path immediately.
1manager.reload()
watchdog
Internal file system observation interface.
Spawned automatically if watch=True is passed.
1manager.start_watching()
Prompt Instance
format()
Executes variable substitution and include resolution.
Mapping of variable keys to runtime values.
If True, raises Exception for missing keys. Default is True.
1prompt = manager.get("summarize")2text = prompt.format({"text": "Hello world"})
partial()
Functional partial application of variables.
Subset of variables to bind permanently.
1bound = prompt.partial({"lang": "Python"})
to_openai_messages()
Ensures output is OpenAI chat completion compatible.
Wraps string-prompts into a 'user' message automatically.
1messages = prompt.to_openai_messages({"user": "Dave"})
to_anthropic_messages()
Formatted for the Anthropic Messages API.
1payload = prompt.to_anthropic_messages({"user": "Dave"})
estimate_tokens()
Offline token counting using provider tokenizers.
'openai' or 'anthropic'.
Tokenizer target model.
1count = prompt.estimate_tokens(model="gpt-4o")
Inspection Methods
Access internal state and metadata.
get_variables()
Returns dict of all variable placeholders.
get_meta()
Returns the _meta dict.
1required = prompt.get_variables()2metadata = prompt.get_meta()
CLI Tools
The library provides a CLI tool named ptm. You can use it to manage your prompts without writing any Python code.
ptm validate
Checks your prompt files for syntax errors, logical errors, and circular dependencies.
Path to a YAML file or directory of YAML files.
Scans the provided source. If there are circular includes (e.g., Prompt A includes Prompt B which includes Prompt A) or invalid YAML syntax, it will report the error.
1ptm validate ./prompts
ptm list
Displays a comprehensive inventory of all loaded prompts.
Path to a YAML file or directory of YAML files.
Outputs a JSON-formatted list of every prompt found in your source. It includes name, versions, variables, and metadata.
1ptm list prompts.yaml
ptm get
Renders the raw content of a specific prompt to your terminal.
Path to a YAML file or directory of YAML files.
Name of the prompt to fetch.
Specific version number.
Specific model tag.
Fetches the specific version of a prompt and prints it. Useful for quickly checking content without opening YAML files.
1ptm get prompts.yaml summarizer --model gpt-4