# PromptML (Prompt Markup Language)
![logo](./logo.png)
<i>A simple, yet elegant markup language for defining AI Prompts as Code (APaC). Built to be used by AI agents to automatically prompt for other AI systems.</i>
## Why PromptML ?
PromptML is built to provide a way for prompt engineers to define the AI prompts in a deterministic way. This is a Domain Specific Language (DSL) which defines characteristics of a prompt including context, objective, instructions and it's metadata.
A regular prompt is an amalgamation of all these aspects into one entity. PromptML splits it into multiple sections and makes the information explicit.
The language grammar can be found here: [grammar.lark](./src/promptml/grammar.lark)
## How PromptML looks ?
The language is simple. You start blocks with `@` section annotation. A section ends with `@end` marker. Comments are started with `#` key. The prompt files ends with `.pml` extension.
```pml
@prompt
# Add task context
@context
@end
# Add task objective
@objective
# This is the final question or ask
@end
# Add one or more instructions to execute the prompt
@instructions
@step
@end
@end
# Add one or more examples
@examples
@example
@input
# Add your example input
@end
@output
# Add your example output
@end
@end
@end
# Add task constraints
@constraints
@length min: 1 max: 10 @end
@end
# Add prompt category
@category
@end
# Add custom metadata
@metadata
@end
@end
```
See [prompt.pml](./prompt.pml) to see for complete syntax.
## Design
Regular text prompts are very abstract in nature. Natural languages are very flexible but provides least reliability. How to provide context for an AI system and ask something ? Shouldn't we specify that explicitly.
PromptML is an attempt to make contents of a prompt explicit with a simple language.
## Core tenets of PromptML
Below are the qualities PromptML brings to prompt engineering domain:
1. Standardization instead of fragmentation
2. Collaboration instead of confusion
3. Enabling version control-ability
4. Promoting verbosity for better results
## Why not use XML, YAML, or JSON for PromptML ?
First, XML, JSON, and YAML are not DSL languages. They are data formats that can represent any form of data. Second, generative AI needs a strict, yet flexible data language with fixed constraints which evolve along with the domain.
PromptML is built exactly to solve those two issues.
Language grammar is influenced by XML & Ruby, so if you know any one of them, you will feel very comfortable writing prompts in PromptML.
## Usage
1. Install Python requirements
```bash
pip install -r requirements.txt
```
2. import the parser and parse a promptML file
```py
from promptml.parser import PromptParser
promptml_code = '''
@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
'''
parser = PromptParser(promptml_code)
prompt = parser.parse()
print(prompt)
# Output: {
# 'context': 'This is the context section.',
# 'objective': 'This is the objective section.',
# 'category': 'Prompt Management',
# 'instructions': ['Step 1'],
# 'examples': [
# {'input': 'Input example 1', 'output': 'Output example 1'}
# ],
# 'constraints': {'length': {'min': 1, 'max': 10}},
# 'metadata': {'top_p': 0.9, 'n': 1, 'team': 'promptml'}
# }
```
## Defining variables
You can define variables in the promptML file and use them in the prompt `context` and `objective`. The variables are defined in the `@vars` section and referenced using `$var` syntax in either `context` or `objective` sections.
```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
```
## Serialization
PromptML document can be serialized into multiple formats like:
1. XML
2. YAML
3. JSON
XML prompts are very-well understood by LLMs and promptML code can be used to generate an XML prompt like this:
From previous example in this README file, we can call a `to_xml()` method on `prompt` object to generate a XML prompt.
```python
# XML
serialized = prompt.to_xml()
print(serialized)
```
Similarly you can generate a YAML or JSON prompt respectively from the same object:
```python
# JSON
prompt.to_json()
# YAML
prompt.to_yaml()
```
## TODO
We are currently working on:
1. `VSCode` syntax highlighting support
2. Add more unit tests
3. Add RAG example
Raw data
{
"_id": null,
"home_page": null,
"name": "promptml",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "artificial-intelligence, dsl, generative-ai, language, prompt-engineering",
"author": null,
"author_email": "\"Vidura Labs Inc.\" <contact@vidura.ai>, Naren Yellavula <naren.yellavula@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/2c/d8/0448ce2b80ab4a8a617c74cf0d646a6b8db6cf8adbebf3afe5f524f19269/promptml-0.6.1.tar.gz",
"platform": null,
"description": "# PromptML (Prompt Markup Language)\n\n![logo](./logo.png)\n\n<i>A simple, yet elegant markup language for defining AI Prompts as Code (APaC). Built to be used by AI agents to automatically prompt for other AI systems.</i>\n\n\n## Why PromptML ?\n\nPromptML is built to provide a way for prompt engineers to define the AI prompts in a deterministic way. This is a Domain Specific Language (DSL) which defines characteristics of a prompt including context, objective, instructions and it's metadata.\nA regular prompt is an amalgamation of all these aspects into one entity. PromptML splits it into multiple sections and makes the information explicit.\n\nThe language grammar can be found here: [grammar.lark](./src/promptml/grammar.lark)\n\n## How PromptML looks ?\n\nThe language is simple. You start blocks with `@` section annotation. A section ends with `@end` marker. Comments are started with `#` key. The prompt files ends with `.pml` extension.\n\n```pml\n@prompt\n # Add task context\n @context\n @end\n\n # Add task objective\n @objective\n # This is the final question or ask\n @end\n\n # Add one or more instructions to execute the prompt\n @instructions\n @step\n @end\n @end\n\n # Add one or more examples\n @examples\n @example\n @input\n # Add your example input\n @end\n @output\n # Add your example output\n @end\n @end\n @end\n\n # Add task constraints\n @constraints\n @length min: 1 max: 10 @end\n @end\n\n # Add prompt category\n @category\n @end\n\n # Add custom metadata\n @metadata\n @end\n@end\n```\n\nSee [prompt.pml](./prompt.pml) to see for complete syntax.\n\n## Design\n\nRegular text prompts are very abstract in nature. Natural languages are very flexible but provides least reliability. How to provide context for an AI system and ask something ? Shouldn't we specify that explicitly.\nPromptML is an attempt to make contents of a prompt explicit with a simple language.\n\n## Core tenets of PromptML\n\nBelow are the qualities PromptML brings to prompt engineering domain:\n\n1. Standardization instead of fragmentation\n2. Collaboration instead of confusion\n3. Enabling version control-ability\n4. Promoting verbosity for better results\n\n## Why not use XML, YAML, or JSON for PromptML ?\n\nFirst, XML, JSON, and YAML are not DSL languages. They are data formats that can represent any form of data. Second, generative AI needs a strict, yet flexible data language with fixed constraints which evolve along with the domain.\n\nPromptML is built exactly to solve those two issues.\n\nLanguage grammar is influenced by XML & Ruby, so if you know any one of them, you will feel very comfortable writing prompts in PromptML.\n\n## Usage\n\n1. Install Python requirements\n\n```bash\npip install -r requirements.txt\n```\n\n2. import the parser and parse a promptML file\n\n```py\nfrom promptml.parser import PromptParser\n\npromptml_code = '''\n @prompt\n @context\n This is the context section.\n @end\n\n @objective\n This is the objective section.\n @end\n\n @instructions\n @step\n Step 1\n @end\n @end\n\n @examples\n @example\n @input\n Input example 1\n @end\n @output\n Output example 1\n @end\n @end\n @end\n\n @category\n Prompt Management\n @end\n\n @constraints\n @length min: 1 max: 10 @end\n @end\n\n @metadata\n top_p: 0.9\n n: 1\n team: promptml\n @end\n @end\n'''\n\nparser = PromptParser(promptml_code)\nprompt = parser.parse()\n\nprint(prompt)\n# Output: {\n# 'context': 'This is the context section.',\n# 'objective': 'This is the objective section.',\n# 'category': 'Prompt Management',\n# 'instructions': ['Step 1'],\n# 'examples': [\n# {'input': 'Input example 1', 'output': 'Output example 1'}\n# ],\n# 'constraints': {'length': {'min': 1, 'max': 10}},\n# 'metadata': {'top_p': 0.9, 'n': 1, 'team': 'promptml'}\n# }\n```\n\n## Defining variables\n\nYou can define variables in the promptML file and use them in the prompt `context` and `objective`. The variables are defined in the `@vars` section and referenced using `$var` syntax in either `context` or `objective` sections.\n\n```pml\n@vars\n name = \"John Doe\"\n@end\n\n@prompt\n @context\n You are a name changing expert.\n @end\n\n @objective\n You have to change the name: $name to an ancient name.\n @end\n@end\n```\n\n\n## Serialization\nPromptML document can be serialized into multiple formats like:\n1. XML\n2. YAML\n3. JSON\n\nXML prompts are very-well understood by LLMs and promptML code can be used to generate an XML prompt like this:\n\nFrom previous example in this README file, we can call a `to_xml()` method on `prompt` object to generate a XML prompt.\n\n```python\n# XML\nserialized = prompt.to_xml()\n\nprint(serialized)\n```\n\nSimilarly you can generate a YAML or JSON prompt respectively from the same object:\n\n```python\n# JSON\nprompt.to_json()\n\n# YAML\nprompt.to_yaml()\n```\n\n## TODO\n\nWe are currently working on:\n\n1. `VSCode` syntax highlighting support\n2. Add more unit tests\n3. Add RAG example\n",
"bugtrack_url": null,
"license": null,
"summary": "A simple, yet elegant markup language for defining AI Prompts as Code (APaC). Built to be used by AI agents to automatically prompt for other AI systems",
"version": "0.6.1",
"project_urls": {
"Documentation": "https://github.com/narenaryan/promptml/blob/main/README.md",
"Issues": "https://github.com/narenaryan/promptml/issues",
"Source": "https://github.com/narenaryan/promptml/"
},
"split_keywords": [
"artificial-intelligence",
" dsl",
" generative-ai",
" language",
" prompt-engineering"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9e3453de0cbd91ae4ebaae89c5094c57a95d03fcd7d3dbbe915b61626b377f69",
"md5": "477d906ccfbd39ca91fff7bde155806a",
"sha256": "33f8b1694dbc9631117e9713a892c92a1026f68bf721e5ac6ca3bae19c0ee9d0"
},
"downloads": -1,
"filename": "promptml-0.6.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "477d906ccfbd39ca91fff7bde155806a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 8191,
"upload_time": "2024-05-25T17:26:10",
"upload_time_iso_8601": "2024-05-25T17:26:10.406308Z",
"url": "https://files.pythonhosted.org/packages/9e/34/53de0cbd91ae4ebaae89c5094c57a95d03fcd7d3dbbe915b61626b377f69/promptml-0.6.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "2cd80448ce2b80ab4a8a617c74cf0d646a6b8db6cf8adbebf3afe5f524f19269",
"md5": "aecc389322981b481f1a602877ead86c",
"sha256": "eeb28ed051b40121b7575681ee13f51b418733633b21c936dc30939f4a1bea9e"
},
"downloads": -1,
"filename": "promptml-0.6.1.tar.gz",
"has_sig": false,
"md5_digest": "aecc389322981b481f1a602877ead86c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 199351,
"upload_time": "2024-05-25T17:26:13",
"upload_time_iso_8601": "2024-05-25T17:26:13.022833Z",
"url": "https://files.pythonhosted.org/packages/2c/d8/0448ce2b80ab4a8a617c74cf0d646a6b8db6cf8adbebf3afe5f524f19269/promptml-0.6.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-25 17:26:13",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "narenaryan",
"github_project": "promptml",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "promptml"
}