PromptML: DSL for AI Prompt Engineering

GitHub Stats Value
Stars 29
Forks 2
Language Python
Created 2024-04-27
License MIT License

PromptML, or Prompt Markup Language, is a simple and elegant markup language designed to define AI prompts in a structured and deterministic way. It allows prompt engineers to break down complex prompts into clear sections such as context, objective, instructions, and metadata, making the information explicit and manageable. This Domain Specific Language (DSL) enables AI agents to automatically generate prompts for other AI systems. With its straightforward syntax using @ section annotations and # comments, PromptML simplifies the process of creating and managing AI prompts, making it a valuable tool for those working in the field of AI prompt engineering.

Overview: PromptML is a simple and elegant markup language designed for defining AI prompts in a deterministic way. It is a Domain Specific Language (DSL) that breaks down AI prompts into explicit sections, making it easier to manage and standardize prompt engineering.

Key Features:

  • Structured Prompts: PromptML splits prompts into sections such as context, objective, instructions, examples, constraints, and metadata, making the information explicit.
  • Syntax: The language uses @ section annotations and @end markers to define blocks. Comments start with #, and files end with the .pml extension.
  • Standardization: Promotes standardization over fragmentation, enabling collaboration and version control.
  • Flexibility: Allows for defining variables and using them within the prompt.
  • Serialization: Prompts can be serialized into XML, YAML, or JSON formats.

Capabilities:

  • Explicit Definition: Makes the contents of a prompt explicit, reducing ambiguity.
  • Collaboration: Facilitates teamwork by providing a clear and standardized way of defining prompts.
  • Version Control: Enables version control of prompts, enhancing reliability and traceability.
  • Custom Metadata: Supports adding custom metadata to prompts.
  • Integration: Can be integrated with AI models like OpenAI and Google models using the promptml-cli.

Usage: Users can install the promptml-cli to run PromptML programs. The language grammar is influenced by XML and Ruby, making it comfortable for users familiar with these languages. PromptML files can be parsed using Python, and the resulting prompts can be serialized into various formats.

PromptML allows you to define AI prompts in a structured and explicit way. Here’s an example of how you can define a prompt using PromptML:

pml

@prompt
    @context
        This is the context section.
    @end

    @objective
        This is the objective section.
    @end

    @instructions
        @step
            Step 1
        @end
    @end

    @examples
        @example
            @input
                Input example 1
            @end
            @output
                Output example 1
            @end
        @end
    @end

    @category
        Prompt Management
    @end

    @constraints
        @length min: 1 max: 10 @end
    @end

    @metadata
        top_p: 0.9
        n: 1
        team: promptml
    @end
@end

You can parse this PromptML code using the PromptParser and use it in your application:

py

from promptml.parser import PromptParser

promptml_code = '''
    @prompt
        ...
'''

parser = PromptParser(promptml_code)
prompt = parser.parse()

print(prompt)

You can define variables in your PromptML files and use them within the prompt:

pml

@vars
    name = "John Doe"
@end

@prompt
    @context
        You are a name changing expert.
    @end

    @objective
        You have to change the name: $name to an ancient name.
    @end
@end

PromptML documents can be serialized into various formats such as XML, YAML, or JSON:

python

## XML
serialized = prompt.to_xml()
print(serialized)

## JSON
prompt.to_json()

## YAML
prompt.to_yaml()
  • Install and Run: Install the promptml-cli to run PromptML programs with OpenAI and Google models.
  • Understand Syntax: Refer to the prompt.pml file for complete syntax and examples.
  • Contribute: The repository is open for contributions, such as adding more unit tests or supporting VSCode syntax

Key Points:

  • Standardization: PromptML introduces a Domain Specific Language (DSL) to standardize AI prompts, reducing fragmentation and confusion.
  • Explicit Structure: It breaks down prompts into explicit sections (context, objective, instructions, examples, constraints, category, and metadata), enhancing reliability and clarity.
  • Collaboration and Version Control: Facilitates collaboration among prompt engineers and enables version control.
  • Flexibility and Constraints: Combines the flexibility of natural languages with the strict constraints needed for generative AI.
  • Serialization: Supports serialization into XML, YAML, and JSON formats.

Future Potential:

  • Integration with IDEs: Planned support for VSCode syntax highlighting will enhance developer experience.
  • Expanded Testing: Addition of more unit tests to ensure robustness.
  • Broader Applications: Potential integration with other AI systems like RAG (Retrieval-Augmented Generation).

PromptML aims to revolutionize prompt engineering by providing a structured, collaborative, and flexible framework for defining AI prompts.

For further insights and to explore the project further, check out the original narenaryan/promptml repository.

Content derived from the narenaryan/promptml repository on GitHub. Original materials are licensed under their respective terms.