Skip to main content

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

signalwire_pom-2.5.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

signalwire_pom-2.5-py2.py3-none-any.whl (11.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file signalwire_pom-2.5.tar.gz.

File metadata

  • Download URL: signalwire_pom-2.5.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.2

File hashes

Hashes for signalwire_pom-2.5.tar.gz
Algorithm Hash digest
SHA256 b8deed533bc386f357304e9862cb91821564b62282cbcd0674d015d8051da64b
MD5 79bfcd8d20574de8e7b4cac996f7a1b8
BLAKE2b-256 7470910d6ea1ef3e52cb76c940541c8af2b40080c242c00f7a7e9b544d68b446

See more details on using hashes here.

File details

Details for the file signalwire_pom-2.5-py2.py3-none-any.whl.

File metadata

  • Download URL: signalwire_pom-2.5-py2.py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.2

File hashes

Hashes for signalwire_pom-2.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8c0a185cfad306c7527eec3cb422cdb3e9106eff80d1002bdd7245a12bf91ec8
MD5 92cb0e2aed295331ddb548977a809d86
BLAKE2b-256 918b7a9f4f3460e1547399434b19c26a8d2f9b05ec0b07c7172bd45b8fc9358a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page