t-prompts
Provenance-preserving prompts for LLMs using Python 3.14's template strings
What is t-prompts?
t-prompts turns Python 3.14+ t-strings into navigable trees that preserve full provenance information (expression text, conversions, format specs). Perfect for building, composing, and auditing LLM prompts.
Unlike f-strings which immediately evaluate to strings, t-prompts keeps the structure intact so you can:
- Trace exactly which variable produced which part of your prompt
- Navigate nested prompt components programmatically
- Compose complex prompts from smaller, reusable pieces
- Audit with complete provenance for compliance and debugging
- Validate types at prompt creation (no accidental
str(obj)surprises)
Requirements: Python 3.14+
Quick Example
from t_prompts import prompt
# Create a structured prompt
instructions = "Always answer politely."
p = prompt(t"Obey {instructions:inst}")
# Renders like an f-string
print(str(p)) # "Obey Always answer politely."
# But preserves full provenance
node = p['inst']
print(node.expression) # "instructions" (original variable name)
print(node.value) # "Always answer politely."
This enables riching tooling:
Targeted Use Cases
- Prompt Debugging: "What exactly did this tangle of code render to?"
- Prompt Optimization (Performance): "What wording / content best achieves my goal?"
- Prompt Optimization (Size): "How do I get the same result with fewer words?"
- Prompt Compacting: "LLM tells me to keep it short, now what do I do?"
Caveats
While this library targets the creation of structured multi-modal prompts, despite the name, there is nothing in particular tying this library to LLMs / Generative models. (It is more "t" than "prompts") To use it for an actual LLM call, you would need to convert the IR into a model specific form (though for text, it could be as simple as str(prompt))
Documentation
📚 Full documentation: https://habemus-papadum.github.io/t-prompts/
Installation
pip install t-prompts
Or with uv:
uv add t-prompts
Development
This project uses UV and PNPM for dependency management.
# Onetime Setup (per dev machine)
curl -LsSf https://astral.sh/uv/install.sh | sh # Other options exist!
curl -fsSL https://get.pnpm.io/install.sh | sh - # Other options exist!
./scripts/setup-visual-tests.sh
# Repo setup (per clone)
./scripts/setup.sh
# Lint and format
uv run ruff check .
uv run ruff format .
# Build documentation
uv run mkdocs serve
See Developer Setup for detailed instructions.
License
MIT License - see LICENSE file for details.
Metadata
Release files for t-prompts 0.18.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| t_prompts-0.18.1.tar.gz | 793.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| t_prompts-0.18.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 2.0 MB
Release files / t_prompts-0.18.1.tar.gz
| Download URL | t_prompts-0.18.1.tar.gz |
|---|---|
| Size | 793.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
945c22cdbeeb472aec267a344800024a59d1a6f595b91e8e76e946a5d8f49631
|
|
BLAKE2b-256 checksum How to use checksums |
b167ef6768f4c8992753ecbb91e8487377201b0c88a206cf46d43213f3279478
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.28.1
|
Release files / t_prompts-0.18.1-py3-none-any.whl
| Download URL | t_prompts-0.18.1-py3-none-any.whl |
|---|---|
| Size | 1.2 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f80bad7e5eaedc7cd839af8c049bc22dec887194467f1cb8d1774a4594a8b1f4
|
|
BLAKE2b-256 checksum How to use checksums |
33b0fe11a21a5a374a7053ca83d2eb4cdaa36dcf2442fc85431238fdb1d2cc77
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.28.1
|