Prompt Object Model - A structured data format for organizing and rendering LLM prompts
Project description
SignalWire Prompt Object Model (POM)
A lightweight Python library for structured prompt management that helps organize and manipulate prompts for large language models (LLMs).
Installation
pip install signalwire-pom
Overview
The Prompt Object Model (POM) is a structured data format and accompanying Python SDK for composing, organizing, and rendering prompt instructions for large language models. It provides a tree-based representation of a prompt document composed of nested sections, each of which can include:
- A title
- A body of explanatory or instructional text
- An optional list of bullet points
- Arbitrarily nested subsections
POM supports multiple output formats including JSON (for machine-readability), Markdown (for human readability), and XML (for structured data exchange), making it ideal for prompt templating, modular editing, and traceable documentation.
Benefits
Structured prompts are essential when building reliable and maintainable LLM instructions. As your prompts evolve, you may need to insert, remove, or rearrange entire sections, subsections, or even individual bullet points. POM enforces a clear hierarchy and semantic organization to ensure that prompts remain modular, auditable, and easy to extend.
1. Clarity and Structure
Prompts can be clearly divided into reusable sections like Objective, Personality, Rules, Knowledge, etc. Each section and subsection can carry detailed instructions and examples.
2. Hierarchical Nesting
Subsections allow nesting of detail and context to any depth, matching how developers and authors think about complex instructions.
3. Markdown Rendering
Documents can be rendered as Markdown with proper heading levels (##, ###, ####, etc.), which is useful for:
- Documentation
- Prompt review and auditing
- Version control and diffs
- Direct inclusion in LLM inputs (most modern LLMs are trained to understand and prioritize Markdown structure)
4. JSON Export and Import
The full prompt specification can be exported and rehydrated in JSON for use in automation, testing, and templating pipelines.
5. XML Rendering
POM documents can also be rendered to XML as an alternative to Markdown. This format is especially useful when your LLM is tuned to expect or parse structured XML data.
6. Extensible
The model is designed to be extensible and can easily incorporate metadata, tags, conditions, or versioning as needed.
Data Structure
Each prompt document consists of a top-level list of Section objects. Each Section has the following structure:
Section
title(str) — The name of the section.body(str, optional) — A paragraph of text associated with the section.bullets(list of str, optional) — Bullet-pointed items.subsections(list of Section objects) — Nested sections with the same structure.numbered(bool, optional) — Whether this section should be numbered.numberedBullets(bool, optional) — Whether bullets should be numbered.
Note: Each section must have at least one of: body, bullets, or subsections. A section containing only a title without any content or nested sections is invalid.
Usage
from signalwire_pom import PromptObjectModel
# Create a new POM
pom = PromptObjectModel()
# Add sections with content
overview = pom.add_section("Overview", body="This is an overview of the project.")
overview.add_bullets(["Point 1", "Point 2", "Point 3"])
# Add subsections
details = overview.add_subsection("Details", body="More detailed information.")
details.add_bullets(["Detail 1", "Detail 2"])
# Creating sections with only subsections (no body or bullets required)
categories = pom.add_section("Categories")
categories.add_subsection("Type A", body="First category description")
categories.add_subsection("Type B", body="Second category description")
# Generate markdown
markdown = pom.render_markdown()
print(markdown)
# Generate JSON representation
json_data = pom.to_json()
print(json_data)
# Generate XML representation
xml_data = pom.render_xml()
print(xml_data)
# Create from JSON
json_string = '''
[
{
"title": "Section from JSON",
"body": "This section was created from JSON",
"bullets": ["Bullet 1", "Bullet 2"],
"subsections": [
{
"title": "Subsection from JSON",
"body": "This subsection was created from JSON",
"bullets": ["Sub-bullet 1", "Sub-bullet 2"],
"subsections": []
}
]
}
]
'''
loaded_pom = PromptObjectModel.from_json(json_string)
print(loaded_pom.render_markdown())
Example JSON Representation
{
"title": "Objective",
"body": "Define the LLM's purpose in this interaction.",
"bullets": ["Summarize clearly", "Answer efficiently"],
"subsections": [
{
"title": "Main Goal",
"body": "Provide helpful and concise answers tailored to user intent.",
"bullets": [],
"subsections": []
}
]
}
Example XML Representation
<?xml version="1.0" encoding="UTF-8"?>
<prompt>
<section>
<title>Objective</title>
<body>Define the LLM's purpose in this interaction.</body>
<bullets>
<bullet>Summarize clearly</bullet>
<bullet>Answer efficiently</bullet>
</bullets>
<subsections>
<section>
<title>Main Goal</title>
<body>Provide helpful and concise answers tailored to user intent.</body>
</section>
</subsections>
</section>
</prompt>
Example Markdown Output
## Objective
Define the LLM's purpose in this interaction.
- Summarize clearly
- Answer efficiently
### Main Goal
Provide helpful and concise answers tailored to user intent.
Features
- Create structured hierarchical prompts
- Add sections, subsections, body text, and bullet points
- Export to markdown, JSON, or XML
- Import from JSON
- Find sections by title
- Numbering support for sections and bullet points
Intended Use Cases
- Designing modular prompt templates
- Explaining prompt logic to collaborators
- Embedding structured prompt metadata in software systems
- Managing evolving prompt strategies across products
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 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 signalwire_pom-2.7.2.tar.gz.
File metadata
- Download URL: signalwire_pom-2.7.2.tar.gz
- Upload date:
- Size: 15.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a62f14b8667ac95ff7085aabc3102fabea729964387c26be676331b5a1bb1dd4
|
|
| MD5 |
981d38fd65fd3ee89a097a684f60d333
|
|
| BLAKE2b-256 |
3069ebf35b07354e9922123e850e525403df439fbe38838ffa3136905c856dfc
|
File details
Details for the file signalwire_pom-2.7.2-py2.py3-none-any.whl.
File metadata
- Download URL: signalwire_pom-2.7.2-py2.py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8cf62c1799c0cebf1b1475d2cebc13cd115dea4aed277a85c6e4c6c43d852cbf
|
|
| MD5 |
5b28cd4d1b98af0e06704039f3ac48fb
|
|
| BLAKE2b-256 |
fbea87e9d040c0912d93d2b9ed6b3d1415793e481663c9a7462350df3cfb3bd7
|