A framework for creating extensible, reusable, and standardized prompts
Project description
Structured Prompt Framework
A framework for creating extensible, reusable, and standardized prompts that can be easily modified by LLMs and adapted across organizations.
Project Goals
This framework addresses the challenge of maintaining consistent, high-quality prompts across teams and AI systems by providing:
- Extensibility - Add new prompt sections and modify existing ones without breaking the core structure and following the same semantic conventions, bullets indentation etc.
- Reusability - Share and compose prompt components across different use cases and teams
- Standardization - Enforce consistent prompt structure and formatting within your organization
- LLM-Friendly - Enable AI systems to understand and modify prompts programmatically
- Self-Introspection (TBD) - Support APIs to evaluate the rendered prompt for inconsistencies and ambiguities
Key Features
🏗️ Hierarchical Stage System
- Define canonical prompt stages in YAML (e.g., Objective, Planning, Execution, Output)
- Auto-generate type-safe, IDE-friendly stage classes
- Support both predefined stages and ad-hoc sections
📝 Flexible Content Assembly
- Mix plain text, structured sections, and nested components
- Append or replace content with clear semantics
- Support metadata like titles, subtitles, and bullet styles
🎯 Organization Templates
- Define organization-specific prompt templates in YAML
- Enforce consistent structure while allowing customization
- Support fixed ordering for critical sections
🔧 Developer Experience
- Full IDE autocompletion and static analysis
- Type-safe stage references
- Clear separation between structure and content
Quick Start
1. Define Your Prompt Structure
Create a YAML file defining your organization's prompt template:
# stages.yaml
stages:
objective:
display: "Objective"
description: "Define the goal and scope"
order: fixed
order_index: 0
planning:
display: "Planning"
description: "Outline the approach"
children:
steps:
display: "Steps"
description: "Detailed execution steps"
execution:
display: "Execution"
description: "How to carry out the plan"
output:
display: "Output"
description: "Format and structure results"
2. Generate Stage Classes
Using the command-line tool:
structured-prompt generate stages.yaml -o src/stages.py
Or programmatically:
from structured_prompt import PromptStructureGenerator
generator = PromptStructureGenerator("stages.yaml")
generator.generate("src/stages.py")
3. Build Your Prompt
The framework supports multiple ways to define a prompt. In most cases assigning an array would extend the existing prompt rather than override it:
from structured_prompt import StructuredPromptFactory, PromptSection
from stages import Stages
# Create a structured prompt
prompt = StructuredPromptFactory(stage_root=Stages)
# Add content to stages
prompt[Stages.Objective] = [
"Analyze the provided incident and identify root causes",
"Provide actionable recommendations for resolution"
]
# Add nested content
prompt[Stages.Planning.Steps] = [
"Start with tracing tools",
"Follow with metrics analysis",
"End with infrastructure investigation"
]
# Add ad-hoc sections
prompt[Stages.Output]["Developer Notes"] = [
"Include code snippets and configuration examples",
"Provide step-by-step resolution instructions"
]
4. Render the Prompt
# Get the formatted prompt
formatted_prompt = prompt.render()
print(formatted_prompt)
Output:
1. Objective
- Analyze the provided incident and identify root causes
- Provide actionable recommendations for resolution
2. Planning
- Investigation Plan
* Review system logs and metrics
* Analyze error patterns and correlations
* Identify potential infrastructure issues
- Steps
* Start with tracing tools
* Follow with metrics analysis
* End with infrastructure investigation
3. Output
- Developer Notes
* Include code snippets and configuration examples
* Provide step-by-step resolution instructions
Architecture
Stage Model (Auto-generated)
- Input: YAML structure definition
- Output: Static Python classes with metadata
- Benefits: IDE autocompletion, type safety, predictable imports
Prompt Assembly Layer
- Purpose: Compose prompts by addressing stages and adding content
- Features:
- Hierarchical addressing (
Stages.Planning.Steps) - Append vs. replace semantics
- Order guarantees for fixed sections
- Idempotent operations
- Hierarchical addressing (
Rendering System
- Purpose: Convert structured content to formatted text
- Features:
- Configurable bullet styles and indentation
- Hanging alignment for multi-line content
- Critical step highlighting
- Customizable formatting preferences
Advanced Usage
Critical Steps
Highlight mandatory actions within your prompt:
prompt.add_critical_step("VERIFY ASSUMPTIONS", "Always validate data sources before proceeding")
prompt[Stages.Execution].add_critical_step("SAFETY CHECK", "Confirm no production impact before changes")
Custom Bullet Styles
Control formatting at the section level:
prompt[Stages.ToolReference] = PromptSection(
bullet_style=None, # No bullets for children
subtitle="Format: [tool|purpose|inputs|notes]",
items=[
"[tracing|service analysis|scope|run first]",
"[metrics|correlation|scope|run after tracing]"
]
)
Fixed Ordering
Ensure critical sections appear in specific positions:
# In your YAML:
tool_reference:
order: fixed
order_index: 3 # Always appears 4th in the prompt
Organization Integration
Template Standardization
- Define Core Template: Create a YAML file with your organization's standard prompt structure
- Generate Stage Classes: Run the generator to create type-safe stage classes
- Distribute: Share the generated classes across teams
- Enforce: Use the framework to ensure all prompts follow the same structure
LLM Modifications
The framework enables AI systems to:
- Understand prompt structure through the stage hierarchy
- Add or modify content while maintaining consistency
- Validate changes against the organization's template
- Generate new prompt variations programmatically
Installation
pip install structured-prompt
For development:
git clone https://github.com/model-labs/structured-prompt
cd structured-prompt
pip install -e ".[dev]"
CLI Reference
The structured-prompt command-line tool provides utilities for working with the framework.
Getting Help
# Show all available commands
structured-prompt --help
# Show help for a specific command
structured-prompt generate --help
Generate Command
Generate Python stage classes from a YAML definition:
# Basic usage
structured-prompt generate stages.yaml -o src/stages.py
# With custom paths
structured-prompt generate config/prompt_structure.yaml -o myapp/prompts/stages.py
Arguments:
input- Path to the input YAML file containing stage definitions-o, --output- Path where the generated Python file should be written
Development
Running Tests
pytest tests/
Linting and Type Checking
# Run ruff linter
ruff check src/
# Run type checker
mypy src/structured_prompt
Generating Stages
Using the CLI tool:
structured-prompt generate stages.yaml -o src/stages.py
Or programmatically:
from structured_prompt import PromptStructureGenerator
generator = PromptStructureGenerator("stages.yaml")
generator.generate("src/stages.py")
Contributing
Contributions are welcome! Please follow these guidelines:
- Fork the repository and create a feature branch
- Follow the existing code structure and patterns
- Add tests for new features (we aim for high test coverage)
- Run the test suite and ensure all tests pass
- Run linters (
ruff check src/) to ensure code quality - Update documentation for API changes
- Submit a pull request with a clear description of changes
CI/CD
All pull requests automatically run:
- Tests on Python 3.13
- Linting with ruff
- Type checking with mypy
- Package build validation
The CI must pass before merging.
Releasing
To create a new release:
-
Create a git tag with the version (e.g.,
v0.3.0):git tag v0.3.0 git push origin v0.3.0
-
Create a GitHub release from the tag
-
The workflow will automatically:
- Extract the version from the tag
- Update
pyproject.tomland__init__.py - Build the package
- Publish to PyPI and TestPyPI
Note: The version in the code doesn't need to be manually updated - it's extracted from the git tag during release.
License
This framework transforms prompt management from an ad-hoc process into a systematic, maintainable system that scales with your organization's needs.
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 structured_prompt-0.2.3.tar.gz.
File metadata
- Download URL: structured_prompt-0.2.3.tar.gz
- Upload date:
- Size: 33.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b579e47b3bbf10c01a5a530587316948e9ff51008a63e8a148bb92a94c42821d
|
|
| MD5 |
0a491fb693670517e7ae6416f09632c9
|
|
| BLAKE2b-256 |
4a9081049666a5376d108bf35a3a23331d5433c2da81504c4e93896ae720671c
|
Provenance
The following attestation bundles were made for structured_prompt-0.2.3.tar.gz:
Publisher:
publish-to-pypi.yml on model-labs/structured-prompt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
structured_prompt-0.2.3.tar.gz -
Subject digest:
b579e47b3bbf10c01a5a530587316948e9ff51008a63e8a148bb92a94c42821d - Sigstore transparency entry: 716910418
- Sigstore integration time:
-
Permalink:
model-labs/structured-prompt@14e520a854bd02734d8d94ecaefada9becad98aa -
Branch / Tag:
refs/tags/v0.2.3 - Owner: https://github.com/model-labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@14e520a854bd02734d8d94ecaefada9becad98aa -
Trigger Event:
release
-
Statement type:
File details
Details for the file structured_prompt-0.2.3-py3-none-any.whl.
File metadata
- Download URL: structured_prompt-0.2.3-py3-none-any.whl
- Upload date:
- Size: 21.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b4efdd19a37a052ffe21f66fe2b22a4fb3a1abbfd58070eeedaeb65ef58676fe
|
|
| MD5 |
a7d1662f93b95be3dec169513d8e8c07
|
|
| BLAKE2b-256 |
6ad35ca45bd07cb3955fa2ee8a5a40afa613b0f3c4d8db35ab6038818a2fc0eb
|
Provenance
The following attestation bundles were made for structured_prompt-0.2.3-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on model-labs/structured-prompt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
structured_prompt-0.2.3-py3-none-any.whl -
Subject digest:
b4efdd19a37a052ffe21f66fe2b22a4fb3a1abbfd58070eeedaeb65ef58676fe - Sigstore transparency entry: 716910421
- Sigstore integration time:
-
Permalink:
model-labs/structured-prompt@14e520a854bd02734d8d94ecaefada9becad98aa -
Branch / Tag:
refs/tags/v0.2.3 - Owner: https://github.com/model-labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@14e520a854bd02734d8d94ecaefada9becad98aa -
Trigger Event:
release
-
Statement type: