Skip to content

signalwire.pom

signalwire.pom

Copyright (c) 2025 SignalWire

This file is part of the SignalWire SDK.

Licensed under the MIT License. See LICENSE file in the project root for full license information.

Prompt Object Model (POM)

A structured data format for organizing and rendering LLM prompts.

Vendored from the signalwire-pom package so the SDK has no external signalwire-pom dependency.

__all__ = ['PromptObjectModel', 'Section'] module-attribute

PromptObjectModel

A structured data format for composing, organizing, and rendering prompt instructions for large language models.

The Prompt Object Model provides a tree-based representation of a prompt document composed of nested sections, each of which can include a title, body text, bullet points, and arbitrarily nested subsections.

This class supports both machine-readability (via JSON/YAML) and structured rendering (via Markdown/XML), making it ideal for prompt templating, modular editing, and traceable documentation.

sections = [] instance-attribute

debug = debug instance-attribute

from_json(json_data) staticmethod

Create a PromptObjectModel instance from JSON data.

Parameters:

Name Type Description Default
json_data str | dict[str, Any] | list[dict[str, Any]]

A JSON string, or already-parsed data (a dict, or a list of section dictionaries as produced by PomBuilder.from_sections)

required

Returns:

Type Description
PromptObjectModel

A new PromptObjectModel populated with the data from the JSON

Raises:

Type Description
ValueError

If the JSON is not properly formatted

from_yaml(yaml_data) staticmethod

Create a PromptObjectModel instance from YAML data.

Parameters:

Name Type Description Default
yaml_data str | dict[str, Any]

Either a YAML string or a parsed dictionary

required

Returns:

Type Description
PromptObjectModel

A new PromptObjectModel populated with the data from the YAML

Raises:

Type Description
ValueError

If the YAML is not properly formatted

__init__(debug=False)

add_section(title=None, *, body='', bullets=None, numbered=None, numberedBullets=False)

Add a top-level section to the model.

Parameters:

Name Type Description Default
title str | None

The title of the section

None
body str

Optional body text for the section

''
bullets list[str] | str | None

Optional list of bullet points or a single string

None
numbered bool | None

Whether this section should be numbered

None
numberedBullets bool

Whether bullets should be numbered

False

Returns:

Type Description
Section

The newly created Section object

Raises:

Type Description
ValueError

If a section without a title is added after the first section

find_section(title)

Find a section by its title.

Performs a recursive search through all sections and subsections.

Parameters:

Name Type Description Default
title str

The title to search for

required

Returns:

Type Description
Section | None

The Section object if found, None otherwise

to_json()

Convert the entire model to a JSON string.

Returns:

Type Description
str

A JSON string representation of the model

to_yaml()

Convert the entire model to a YAML string.

Returns:

Type Description
str

A YAML string representation of the model

to_dict()

Convert the entire model to a list of dictionaries.

Returns:

Type Description
list[dict[str, Any]]

A list of dictionaries representing the model

render_markdown()

Render the entire model as markdown.

Returns:

Type Description
str

A string containing the markdown representation

render_xml()

Render the entire model as XML.

Returns:

Type Description
str

A string containing the XML representation

add_pom_as_subsection(target, pom_to_add)

Add another PromptObjectModel as a subsection to a section with the given title or section object.

Parameters:

Name Type Description Default
target str | Section

The title of the section or the Section object to which the POM should be added as a subsection.

required
pom_to_add PromptObjectModel

The PromptObjectModel to add as a subsection.

required

Raises:

Type Description
ValueError

If no section with the target title is found (when target is a string).

Section

Represents a section in the Prompt Object Model.

Each section contains a title, optional body text, optional bullet points, and can have any number of nested subsections.

Attributes:

Name Type Description
title str

The name of the section.

body str

A paragraph of text associated with the section.

bullets List[str]

Bullet-pointed items.

subsections List[Section]

Nested sections with the same structure.

numbered bool

Whether this section should be numbered.

numberedBullets bool

Whether bullets should be numbered instead of using bullet points.

title = title instance-attribute

body = body instance-attribute

bullets = bullets or [] instance-attribute

subsections = [] instance-attribute

numbered = numbered instance-attribute

numberedBullets = numberedBullets instance-attribute

__init__(title=None, *, body='', bullets=None, numbered=None, numberedBullets=False)

add_body(body)

Add or replace the body text for this section.

add_bullets(bullets)

Add bullet points to this section.

add_subsection(title, *, body='', bullets=None, numbered=False, numberedBullets=False)

Add a subsection to this section.

Parameters:

Name Type Description Default
title str

The title of the subsection

required
body str

Optional body text for the subsection

''
bullets list[str] | None

Optional list of bullet points

None
numbered bool

Whether this section should be numbered

False
numberedBullets bool

Whether bullets should be numbered

False

Returns:

Type Description
Section

The newly created Section object

Raises:

Type Description
ValueError

If the title is None or if the section has neither a body nor bullets

to_dict()

Convert the section to a dictionary representation.

render_markdown(level=2, section_number=None)

Render this section and all its subsections as markdown.

Parameters:

Name Type Description Default
level int

The heading level to start with (default: 2, which corresponds to ##)

2
section_number list[int] | None

The current section number for numbered sections

None

Returns:

Type Description
str

A string containing the markdown representation

render_xml(indent=0, section_number=None)

Render this section and all its subsections as XML.

Parameters:

Name Type Description Default
indent int

The indentation level to start with (default: 0)

0
section_number list[int] | None

The current section number for numbered sections

None

Returns:

Type Description
str

A string containing the XML representation

pom

Section

Represents a section in the Prompt Object Model.

Each section contains a title, optional body text, optional bullet points, and can have any number of nested subsections.

Attributes:

Name Type Description
title str

The name of the section.

body str

A paragraph of text associated with the section.

bullets List[str]

Bullet-pointed items.

subsections List[Section]

Nested sections with the same structure.

numbered bool

Whether this section should be numbered.

numberedBullets bool

Whether bullets should be numbered instead of using bullet points.

title = title instance-attribute
body = body instance-attribute
bullets = bullets or [] instance-attribute
subsections = [] instance-attribute
numbered = numbered instance-attribute
numberedBullets = numberedBullets instance-attribute
__init__(title=None, *, body='', bullets=None, numbered=None, numberedBullets=False)
add_body(body)

Add or replace the body text for this section.

add_bullets(bullets)

Add bullet points to this section.

add_subsection(title, *, body='', bullets=None, numbered=False, numberedBullets=False)

Add a subsection to this section.

Parameters:

Name Type Description Default
title str

The title of the subsection

required
body str

Optional body text for the subsection

''
bullets list[str] | None

Optional list of bullet points

None
numbered bool

Whether this section should be numbered

False
numberedBullets bool

Whether bullets should be numbered

False

Returns:

Type Description
Section

The newly created Section object

Raises:

Type Description
ValueError

If the title is None or if the section has neither a body nor bullets

to_dict()

Convert the section to a dictionary representation.

render_markdown(level=2, section_number=None)

Render this section and all its subsections as markdown.

Parameters:

Name Type Description Default
level int

The heading level to start with (default: 2, which corresponds to ##)

2
section_number list[int] | None

The current section number for numbered sections

None

Returns:

Type Description
str

A string containing the markdown representation

render_xml(indent=0, section_number=None)

Render this section and all its subsections as XML.

Parameters:

Name Type Description Default
indent int

The indentation level to start with (default: 0)

0
section_number list[int] | None

The current section number for numbered sections

None

Returns:

Type Description
str

A string containing the XML representation

PromptObjectModel

A structured data format for composing, organizing, and rendering prompt instructions for large language models.

The Prompt Object Model provides a tree-based representation of a prompt document composed of nested sections, each of which can include a title, body text, bullet points, and arbitrarily nested subsections.

This class supports both machine-readability (via JSON/YAML) and structured rendering (via Markdown/XML), making it ideal for prompt templating, modular editing, and traceable documentation.

sections = [] instance-attribute
debug = debug instance-attribute
from_json(json_data) staticmethod

Create a PromptObjectModel instance from JSON data.

Parameters:

Name Type Description Default
json_data str | dict[str, Any] | list[dict[str, Any]]

A JSON string, or already-parsed data (a dict, or a list of section dictionaries as produced by PomBuilder.from_sections)

required

Returns:

Type Description
PromptObjectModel

A new PromptObjectModel populated with the data from the JSON

Raises:

Type Description
ValueError

If the JSON is not properly formatted

from_yaml(yaml_data) staticmethod

Create a PromptObjectModel instance from YAML data.

Parameters:

Name Type Description Default
yaml_data str | dict[str, Any]

Either a YAML string or a parsed dictionary

required

Returns:

Type Description
PromptObjectModel

A new PromptObjectModel populated with the data from the YAML

Raises:

Type Description
ValueError

If the YAML is not properly formatted

__init__(debug=False)
add_section(title=None, *, body='', bullets=None, numbered=None, numberedBullets=False)

Add a top-level section to the model.

Parameters:

Name Type Description Default
title str | None

The title of the section

None
body str

Optional body text for the section

''
bullets list[str] | str | None

Optional list of bullet points or a single string

None
numbered bool | None

Whether this section should be numbered

None
numberedBullets bool

Whether bullets should be numbered

False

Returns:

Type Description
Section

The newly created Section object

Raises:

Type Description
ValueError

If a section without a title is added after the first section

find_section(title)

Find a section by its title.

Performs a recursive search through all sections and subsections.

Parameters:

Name Type Description Default
title str

The title to search for

required

Returns:

Type Description
Section | None

The Section object if found, None otherwise

to_json()

Convert the entire model to a JSON string.

Returns:

Type Description
str

A JSON string representation of the model

to_yaml()

Convert the entire model to a YAML string.

Returns:

Type Description
str

A YAML string representation of the model

to_dict()

Convert the entire model to a list of dictionaries.

Returns:

Type Description
list[dict[str, Any]]

A list of dictionaries representing the model

render_markdown()

Render the entire model as markdown.

Returns:

Type Description
str

A string containing the markdown representation

render_xml()

Render the entire model as XML.

Returns:

Type Description
str

A string containing the XML representation

add_pom_as_subsection(target, pom_to_add)

Add another PromptObjectModel as a subsection to a section with the given title or section object.

Parameters:

Name Type Description Default
target str | Section

The title of the section or the Section object to which the POM should be added as a subsection.

required
pom_to_add PromptObjectModel

The PromptObjectModel to add as a subsection.

required

Raises:

Type Description
ValueError

If no section with the target title is found (when target is a string).

pom_tool

POM Tool - Command line utility for working with Prompt Object Model files

Usage

pom_tool [--output=][--outfile=] [--merge_pom="

:"] pom_tool (-h | --help)

Options

-h --help Show this help message --output= Output format: md, xml, json, yaml [default: md] --outfile= Output file (if not specified, prints to stdout) --merge_pom= Merge another POM into a section: "

:"

detect_file_format(file_path)

Detect if the file is JSON or YAML based on extension and content.

load_pom(file_path)

Load a POM from a file, auto-detecting the format.

render_pom(pom, output_format)

Render the POM in the specified format.

main()

Main entry point for the POM tool.