Strompt
Introduction
Strompt (structured prompts) is an opinionated, extensible, zero-dependency prompt rendering library. Strompt is designed to enable the construction of consistent, reusable prompts in agentic applications.
The goal of Strompt is to create prompts that are readable (easy to debug), correct (typo-free), and maintainable.
This is the Python port of Strompt. A JavaScript/TypeScript version with identical rendering is available on npm at @4arch/strompt.
Installation
The library can be installed directly from PyPI at strompt with any Python package manager, examples for pip and uv are provided below:
pip install strompt # pip installation
or
uv add strompt # uv installation
Strompt supports Python 3.11 and above.
Usage
Consider the following prompt:
def generate_refund_prompts(user_info: list[str], user_prompt: str) -> tuple[str, str]:
system_prompt = """You are a customer support agent working at ACME designed to review refund requests and determine whether they are valid or invalid. Your aim is to create the best possible customer experience while also ensuring that fraudulent or unqualified refund requests are not granted. You respond in a tone that is formal and polite but not utterly deferential to the user.
To make your decision, you will be provided with the customer's refund request and a list of statistics about the customer, such as how long their account has existed and how many prior purchases they have completed.
Your output should be the amount of money to refund the user given their request. Adhere to the following rules:
1. Output ONLY the refund amount and nothing else
2. The refund amount should be expressed in USD cents, so if a $1.50 refund should be granted the output should be 150
3. If no refund should be granted, simply output 0
4. Accounts that have no successful prior purchases or have only been active for a short period of time are more likely to be fraudulent, so be extra careful when evaluating refund requests from such accounts
5. Use your available tools to double check a user's refund request reasoning (ex. if the user claims the package was delivered late, use your package lookup tool to confirm this is accurate)."""
prompt = f"User refund request: {user_prompt}\nUser Background Info: {','.join(user_info)}"
return system_prompt, prompt
These prompts are blocks of text, and are thus fairly difficult to read and maintain. Moreover, it's easy to make typos like messing up the numbering of the output instructions in the process of adding/editing bullets. It is also hard to see whitespace, such as the \n separating the sections of the prompt.
In Strompt, the prompt is much cleaner to read and maintain:
from strompt import MarkdownPromptRenderer
def generate_refund_prompts(user_info: list[str], user_prompt: str) -> tuple[str, str]:
system_prompt = MarkdownPromptRenderer()
with system_prompt.section("personality") as personality:
with personality.subsection("Background") as background:
background.text(
"You are a customer support agent working at ACME designed to review refund "
"requests and determine whether they are valid or invalid. You respond in a "
"tone that is formal and polite but not utterly deferential to the user."
)
with system_prompt.section("task") as task:
with task.subsection("Description") as description:
description.text(
"Your aim is to create the best possible customer experience while also "
"ensuring that fraudulent or unqualified refund requests are not granted."
)
with task.subsection("Output") as output:
output.text(
"Your output should be the amount of money to refund the user given their "
"request."
)
with task.subsection("Guidelines") as guidelines:
with guidelines.ordered_list("Adhere to the following rules") as rules:
rules.bullet("Output ONLY the refund amount and nothing else")
rules.bullet(
"The refund amount should be expressed in USD cents, so if a $1.50 "
"refund should be granted the output should be 150"
)
rules.bullet("If no refund should be granted, simply output 0")
rules.bullet(
"Accounts that have no successful prior purchases or have only been "
"active for a short period of time are more likely to be fraudulent, so "
"be extra careful when evaluating refund requests from such accounts"
)
rules.bullet(
"Use your available tools to double check a user's refund request "
"reasoning (ex. if the user claims the package was delivered late, use "
"your package lookup tool to confirm this is accurate)."
)
prompt = MarkdownPromptRenderer()
with prompt.section("user request") as request:
request.subsection("Refund Request", lambda sub: sub.text(user_prompt))
request.subsection(
"User Background Info", lambda sub: sub.text(",".join(user_info))
)
return system_prompt.render(), prompt.render()
As can be seen, Strompt uses the Fluid Builder design pattern to sequentially construct prompts. Every builder method can be used in one of two ways:
- Without a callback, it returns the node it created, which can be populated within a
withblock - With a callback, it runs the callback on the node it created and returns the parent, so that calls can be chained
The prompt is now much easer to read, as we can quickly jump to the sections we are looking for simply by glancing at the relevant section headers.
Calling .render() also automatically applies markdown styling and list numbering, the output of the prompts above is:
System Prompt
<personality>
# Background
You are a customer support agent working at ACME designed to review refund requests and determine whether they are valid or invalid. You respond in a tone that is formal and polite but not utterly deferential to the user.
</personality>
<task>
# Description
Your aim is to create the best possible customer experience while also ensuring that fraudulent or unqualified refund requests are not granted.
# Output
Your output should be the amount of money to refund the user given their request.
# Guidelines
Adhere to the following rules:
1. Output ONLY the refund amount and nothing else
2. The refund amount should be expressed in USD cents, so if a $1.50 refund should be granted the output should be 150
3. If no refund should be granted, simply output 0
4. Accounts that have no successful prior purchases or have only been active for a short period of time are more likely to be fraudulent, so be extra careful when evaluating refund requests from such accounts
5. Use your available tools to double check a user's refund request reasoning (ex. if the user claims the package was delivered late, use your package lookup tool to confirm this is accurate).
</task>
Prompt:
<user request>
# Refund Request
{refund request}
# User Background Info
{background info}
</user request>
Extensibility
Strompt is designed to be fully extensible, enabling you to override or even define your own Prompt Renderers.
Currently, the only implemented renderer is MarkdownPromptRenderer, which renders prompts in Markdown.
To build a custom renderer for specific nodes, you can override the prompt renderer's rendering strategy using the override_spec method:
from strompt import MarkdownPromptRenderer
custom_renderer = MarkdownPromptRenderer()
custom_renderer.override_spec(
# Render all .text() nodes in uppercase
render_section_text=lambda text: text.upper(),
)
You can also define a new renderer from scratch simply by subclassing the PromptRenderer base class and passing a complete PromptRendererSpec to the super constructor.
Metadata
Release files for strompt 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| strompt-0.1.0.tar.gz | 8.3 kB | With provenance | Details for strompt-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| strompt-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for strompt-0.1.0-py3-none-any.whl |
Total release size: 18.1 kB
Release files / strompt-0.1.0.tar.gz
| Download URL | strompt-0.1.0.tar.gz |
|---|---|
| Size | 8.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0dd8d15994f16402bb8d0608193e03a4ecd74314d6dc7e81ecffc6191198e13d
|
|
BLAKE2b-256 checksum How to use checksums |
b44dd1f2f6b400e5e74e491200eec50dec22000d0223110c0fcba25b8f79c406
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.
Transparency logRelease files / strompt-0.1.0-py3-none-any.whl
| Download URL | strompt-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c7752b57d3c99df3f315d65d5ed47820020735a74bd5d54ffb3343bbaf59e03c
|
|
BLAKE2b-256 checksum How to use checksums |
94f88c879787dc231e7f009b66d42333738ccc3e09083739f554c01380a5287d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.
Transparency logSecurity for strompt 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for strompt-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.