A lightweight, modular library for building, composing, and managing structured prompts for LLMs
Project description
Prompting Forge
A simple, focused library for creating and versioning prompt templates.
Core Concept
PromptTemplate is the central object that:
- Defines a prompt with a system message and template with Python-style
{placeholders} - Automatically saves versions to
.prompt/{instance_name}/{instance_name}__prompt__v{version}.json - Extracts variables from the template automatically
- Smart versioning: Only creates a new version if the prompt changes (compares system, template, and variables)
Version Management
- First instantiation: Creates v1
- Identical prompt: Reuses existing version (no duplicate saved)
- Modified prompt: Increments version number (v2, v3, etc.)
- Clear feedback: Displays whether a new version was created or an existing one was reused
Quick Start
from prompting_forge.prompting import PromptTemplate
# Create a prompt template with an instance name to save it
template = PromptTemplate(
system="You are a helpful assistant.",
template="Answer the following question about {topic}: {question}",
instance_name="my_prompt",
)
# The template is automatically saved to:
# .prompt/my_prompt/my_prompt__prompt__v1.json
Directory Structure
prompting-forge/
├── prompting_forge/
│ ├── __init__.py
│ ├── prompting/
│ │ ├── __init__.py
│ │ └── prompt.py # Core PromptTemplate class
│ └── versioning.py # Version saving logic
├── example.py # Simple example
└── README.md
Saved Prompt Format
When you instantiate a PromptTemplate with an instance_name, it saves a JSON file:
{
"ts": "2025-11-12T10:30:00.000000+00:00",
"instance": "my_prompt",
"version": 1,
"system": "You are a helpful assistant.",
"template": "Answer the following question about {topic}: {question}",
"variables": ["question", "topic"]
}
Example
Run the example:
python example.py
First run (creates v1):
✓ New prompt version created: v1
Saved to: C:\...\prompting-forge\.prompt\prompting_example\prompting_example__prompt__v1.json
Template variables: ['impact', 'rca_hypothesis', 'severity', 'stakeholders', 'title']
Second run (detects identical prompt):
⊙ Prompt unchanged - using existing version: v1
Location: C:\...\prompting-forge\.prompt\prompting_example\prompting_example__prompt__v1.json
Template variables: ['impact', 'rca_hypothesis', 'severity', 'stakeholders', 'title']
After modifying the template (creates v2):
✓ New prompt version created: v2
Saved to: C:\...\prompting-forge\.prompt\prompting_example\prompting_example__prompt__v2.json
Template variables: [...]
Test Versioning Behavior
Run the comprehensive test to see all versioning scenarios:
python test_versioning.py
This demonstrates:
- Creating initial version (v1)
- Reusing identical prompts (stays at v1)
- Creating new versions when content changes (v2, v3, etc.)
- Comparing system messages, templates, and variables
Complete Workflow Example
Run the full synthesis workflow:
python example_final_synthesis.py
This shows:
- Creating multiple prompt versions iteratively
- Using
FinalPromptTemplateto synthesize with LLM - Using the final prompt in production
Final Prompt Synthesis
After creating multiple prompt versions, use FinalPromptTemplate to synthesize an optimized final prompt using an LLM:
from prompting_forge.prompting import PromptTemplate, FinalPromptTemplate
from genai_forge import get_llm
# Create multiple versions
v1 = PromptTemplate(
system="You are a helper.",
template="Help with {task}.",
instance_name="my_assistant",
)
v2 = PromptTemplate(
system="You are an expert helper.",
template="Provide detailed help with {task} for {audience}.",
instance_name="my_assistant",
)
# Synthesize final prompt from all versions
llm = get_llm("openai:gpt-4o-mini")
final = FinalPromptTemplate(
instance_name="my_assistant",
variables=["task", "audience"], # Variables you want in final template
llm_client=llm,
)
# The LLM analyzes all versions and creates an optimized final prompt
# Saved to: .prompt/my_assistant/final_prompt.json
How It Works
- Collects all versions: Reads all
{instance_name}__prompt__v*.jsonfiles - LLM synthesis: Uses
PromptTemplate+LLMCallto analyze versions - Creates optimized prompt: LLM generates system message and template
- Validates variables: Ensures all required variables are in the final template
- Saves final prompt: Stores as
final_prompt.json(version -1) - Reuses if exists: Subsequent instantiations use the existing final prompt
API Reference
PromptTemplate
Parameters:
system(Optional[str]): System message for the prompttemplate(str): Template string with{variable}placeholdersvariables(Optional[Iterable[str]]): Explicit variable list (auto-detected if not provided)instance_name(Optional[str]): Name for saving versions (creates.prompt/{instance_name}/directory)version_root(Optional[Path]): Root directory for.prompt/(defaults to current directory)
Methods:
format(variables, instructions=None)→ChatPrompt: Format the template with variable valuesrender(context, strict=True)→str: Render template to plain stringexpected_variables()→Set[str]: Get the set of variables in the template
FinalPromptTemplate
Parameters:
instance_name(str): Name of the prompt instance to synthesizevariables(List[str]): Variable names the final template must usellm_client: LLM client from genai-forgesynthesis_instructions(Optional[str]): Custom instructions for synthesisversion_root(Optional[Path]): Root directory for.prompt/folder
Requirements:
- At least 2 prompt versions must exist for the instance
- Uses
PromptTemplate+LLMCallinternally for synthesis
Inherits from: BasePromptTemplate (has same methods as PromptTemplate)
ChatPrompt
Simple dataclass representing a formatted prompt:
system(Optional[str]): System messageuser(str): User messageto_messages()→list[dict]: Convert to message format for LLM APIs
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 Distribution
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 prompting_forge-0.1.10.tar.gz.
File metadata
- Download URL: prompting_forge-0.1.10.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58c728773833553857e7c1bfc6b9bf2233470337fa1fcbb6fa21121af6c26662
|
|
| MD5 |
fccccfa56db9d45f16ce89f311741290
|
|
| BLAKE2b-256 |
6556f9621a37b4531589a108d0debfec6237ad8ef146a084c56ff9d99c95d851
|
Provenance
The following attestation bundles were made for prompting_forge-0.1.10.tar.gz:
Publisher:
release.yml on ToolForge-AI/prompting-forge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
prompting_forge-0.1.10.tar.gz -
Subject digest:
58c728773833553857e7c1bfc6b9bf2233470337fa1fcbb6fa21121af6c26662 - Sigstore transparency entry: 697482888
- Sigstore integration time:
-
Permalink:
ToolForge-AI/prompting-forge@d32bbc264c3f8779fa58adbd2bad30cadd4c92a5 -
Branch / Tag:
refs/tags/0.1.10 - Owner: https://github.com/ToolForge-AI
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d32bbc264c3f8779fa58adbd2bad30cadd4c92a5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file prompting_forge-0.1.10-py3-none-any.whl.
File metadata
- Download URL: prompting_forge-0.1.10-py3-none-any.whl
- Upload date:
- Size: 14.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5fc7b14a9db80f9620c77b29be285bda81d449fdb4b6980c85433c883bcf672c
|
|
| MD5 |
a74e58a6ace238f1b0740085e63a0d79
|
|
| BLAKE2b-256 |
a1539f1787a6fc99ec269045f2351a3d926b7a6aa6833466d9bf7fca5b242bc0
|
Provenance
The following attestation bundles were made for prompting_forge-0.1.10-py3-none-any.whl:
Publisher:
release.yml on ToolForge-AI/prompting-forge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
prompting_forge-0.1.10-py3-none-any.whl -
Subject digest:
5fc7b14a9db80f9620c77b29be285bda81d449fdb4b6980c85433c883bcf672c - Sigstore transparency entry: 697482917
- Sigstore integration time:
-
Permalink:
ToolForge-AI/prompting-forge@d32bbc264c3f8779fa58adbd2bad30cadd4c92a5 -
Branch / Tag:
refs/tags/0.1.10 - Owner: https://github.com/ToolForge-AI
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d32bbc264c3f8779fa58adbd2bad30cadd4c92a5 -
Trigger Event:
push
-
Statement type: