Prompt Orchestration Markup Language

repository·main·Indexed 26 days ago

https://github.com/microsoft/poml

A structured markup language for advanced prompt engineering that decouples content from presentation. POML allows developers to organize prompt components and integrate data such as text, tables, and images. The ecosystem includes the poml and pomljs packages for Python and Node.js, a VS Code extension for LLM testing, and Prompt Scratchpad, a WYSIWYG browser extension for assembling complex prompts via a block-based composition canvas.

Tokens
35.9K
Snippets
126
Records
229
Agent score
88%

What's inside POML

  1. Overview of Prompt Scratchpad (POML browser extension)

    main

    Prompt Scratchpad is a WYSIWYG (What You See Is What You Get) prompt workspace designed as a browser sidebar extension (Chrome/Edge). It allows users to assemble complex, multi-source prompts by dragging in webpages, documents, code, and media into a 'Prompt Drafting Canvas'.

    Key capabilities include:

    • Block-based composition: Arrange different types of content (instructions, web captures, code, tables, etc.) as reorderable blocks.
    • Zero-markup authoring: Uses POML (Prompt Orchestration Markup Language) under the hood, but users interact with a visual interface without needing to write tags.
    • High-fidelity dispatch: One-click copy of the rendered prompt to the clipboard for easy pasting into LLMs like ChatGPT, Gemini, or Claude.
    • Formatting preservation: Maintains structure for tables and code snippets to ensure LLMs receive clean, contextually accurate data.

    Note: This project is currently under development and is not yet available in the Chrome Web Store.

  2. Overview of POML (Prompt Orchestration Markup Language)

    main

    POML is a structured markup language designed for advanced prompt engineering for Large Language Models (LLMs). It uses an HTML-like syntax to organize prompt components, making them modular, reusable, and maintainable.

    Key capabilities include:

    • Structured Prompting: Uses semantic components like <role>, <task>, and <example>.
    • Data Integration: Specialized tags like <document>, <table, and <img for embedding external data.
    • Decoupled Styling: A CSS-like system to separate prompt content from presentation (e.g., verbosity or syntax format) via <stylesheet> or inline attributes.
    • Templating Engine: Supports variables ({{ }}), loops (for), conditionals (if), and variable definitions (<let>).
  3. Use meta-like components for prompt rendering

    main

    POML supports 'meta-like' components that affect prompt rendering and LLM execution without appearing in the final prompt messages. These components are used for configuration that should be invisible to the LLM but functional for the runtime. Examples include:

    • <stylesheet>
    • <output-schema>
    • <tool-definition>
    • <runtime>
  4. Create a basic POML file

    main

    To get started with POML, create a file with a .poml extension (e.g., example.poml). A standard POML file uses an XML-like structure to define a role, a task, optional media assets (like <img>), and an output-format. Ensure any referenced local assets, such as images, are in the same directory as the .poml file.

    <poml>
      <role>You are a patient teacher explaining concepts to a 10-year-old.</role>
      <task>Explain the concept of photosynthesis using the provided image as a reference.</task>
    
      <img src="photosynthesis_diagram.png" alt="Diagram of photosynthesis" />
    
      <output-format>
        Keep the explanation simple, engaging, and under 100 words.
        Start with "Hey there, future scientist!".
      </output-format>
    </poml>
  5. Handle whitespace when using specific syntaxes

    main

    The whiteSpace attribute controls whitespace handling when rendering to the Intermediate Representation (IR). However, when converting the IR to specific formats like Markdown, JSON, or XML, the target format's syntax rules may still affect the output.

    To ensure whitespace is kept exactly as intended, use syntax="text" combined with whiteSpace="pre". Note that when using syntax="text", you cannot use nested tags like <p> within the content.

    <poml syntax="text" whiteSpace="pre">
  6. Use mixed content in POML files

    main

    The extended POML format allows you to mix pure text (like Markdown) with POML markup elements in a single file. This removes the requirement for files to be entirely wrapped in <poml>...</poml> tags.

    Supported Content Types

    • Pure Text Content: Regular Markdown or plain text.
    • POML Element Pairs: Any valid component defined in componentDocs.json (e.g., <task>...</task>, <p>...</p>).
    • Mixed Content: A combination of the above.

    Escaping POML Tags in Text

    To display a POML tag as literal text without it being parsed as a component, wrap it in a <text> tag. To escape a specific pair like <poml>...</poml>, use the following pattern:

    <text><poml></text>...<text></poml></text>
    # My Analysis Document
    
    This is a regular markdown document that explains the task.
    
    <task>
      Analyze the following data and provide insights.
    </task>
    
    Here are some key points to consider:
    
    - Data quality
    - Statistical significance
    - Business impact
    
    <examples>
      <example>
        <input>Sample data point 1</input>
        <output>Analysis result 1</output>
      </example>
    </examples>
    
    ## Conclusion
    
    The analysis shows...
  7. Configure LLM for prompt testing in VS Code

    main
    To use the Model Testing feature within the POML VS Code extension, you must configure your preferred LLM model, API key, and endpoint. If these settings are not configured, prompt testing will fail. Refer to the specific configuration instructions in the documentation for setup details.
  8. Run the Travel Expense Agent complete example

    main

    The full implementation of the Travel Expense Agent workflow is provided in the repository examples. You can run the complete Python script to see the end-to-end process of document extraction, rule identification, compliance checking, and email generation.

    python 404_travel_expense_agent.py
  9. Install the POML Python SDK (Nightly Build)

    main

    To install the latest nightly build of the POML Python SDK, use the following command which points to the test PyPI index.

    pip install --upgrade --pre --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ poml
  10. Enable tracing in Python for POML calls

    main

    To capture a comprehensive audit trail of every interaction with the LLM, enable tracing in your Python application using poml.set_trace(). This creates a directory containing the POML source, context variables, rendered outputs, and environment metadata (the "crime scene").

    Note: It is recommended to add the specified trace directory to your .gitignore to avoid committing trace data to version control.

    import poml
    
    # Enable tracing for all POML calls
    poml.set_trace(trace_dir="pomlruns")
  11. Loop over lists using the for attribute

    main

    To iterate over a list, use the for attribute with the syntax for="itemName in listName".

    Inside the loop, you have access to the loop object:

    • loop.index: Current iteration index (starts at 0).
    • loop.length: Total number of items.
    • loop.first: true if it's the first item.
    • loop.last: true if it's the last item.
    <poml>
      <list>
        <item for="item in ['apple', 'banana', 'cherry']">{{item}}</item>
      </list>
    </poml>