Skip to main content

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:

  1. Extensibility - Add new prompt sections and modify existing ones without breaking the core structure and following the same semantic conventions, bullets indentation etc.
  2. Reusability - Share and compose prompt components across different use cases and teams
  3. Standardization - Enforce consistent prompt structure and formatting within your organization
  4. LLM-Friendly - Enable AI systems to understand and modify prompts programmatically
  5. 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

from src.generator.prompt_structure_generator 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 src.builder.dynamic_prompt_builder import DigmaStructuredPrompt, PromptSection
from src.stages import Stages

# Create a structured prompt
prompt = DigmaStructuredPrompt(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

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

  1. Define Core Template: Create a YAML file with your organization's standard prompt structure
  2. Generate Stage Classes: Run the generator to create type-safe stage classes
  3. Distribute: Share the generated classes across teams
  4. 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 -r requirements.txt

Development

Running Tests

python -m pytest tests/

Generating Stages

python -m src.generator.prompt_structure_generator --input stages.yaml --output src/stages.py

Contributing

  1. Follow the existing code structure and patterns
  2. Add tests for new features
  3. Update documentation for API changes
  4. Ensure generated code follows the established format

License

MIT


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

structured_prompt-0.1.0.tar.gz (28.4 kB view details)

Uploaded Source

Built Distribution

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

structured_prompt-0.1.0-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file structured_prompt-0.1.0.tar.gz.

File metadata

  • Download URL: structured_prompt-0.1.0.tar.gz
  • Upload date:
  • Size: 28.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for structured_prompt-0.1.0.tar.gz
Algorithm Hash digest
SHA256 43384a659fdb035035ce2bebb160e0abcd7012f4ebcb1c4db7c31e7dd103c33f
MD5 1a473fd17d294b8a7193ee0485534d04
BLAKE2b-256 e5b4c7cf65d57e2288f2b7650b8ce0ae5146b51be9f5d8f288efa0b483d4098f

See more details on using hashes here.

Provenance

The following attestation bundles were made for structured_prompt-0.1.0.tar.gz:

Publisher: publish-to-pypi.yml on model-labs/structured-prompt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file structured_prompt-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for structured_prompt-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fc38907def81ab22119784561f1f63fe03e347143f01319d4b19c91aa6a3e5f6
MD5 02c6bab2355e80a102c44d0f47aa0666
BLAKE2b-256 81d72ca37ee93cbaad17ddc698fc5eda9c2d991430ae68f10459ca9d14e0a611

See more details on using hashes here.

Provenance

The following attestation bundles were made for structured_prompt-0.1.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on model-labs/structured-prompt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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