Features ✨
- 🎯 Jinja-Powered Templates: Leverage the full power of Jinja2 templating for dynamic prompt generation
- 🎭 Role-Based Messaging: Structure conversations with system, user, assistant, and tool roles
- 🤖 Pydantic-AI Compatible: Returns structured pydantic-ai ModelMessage objects for seamless integration
- 🔄 Format Conversion: Convert to OpenAI chat API (or other APIs) through pydantic-ai's message mapping
Installation 📦
pip install prompt-bottle
Quick Start 🚀
Basic Usage
from prompt_bottle import render
# Simple template
template = """
You are a helpful assistant.
<div role="user">{{ user_message }}</div>
"""
messages = render(template, user_message="Hello, world!")
print(messages)
Core Concepts 📚
Template Example
You are a helpful assistant.
{{ system_instructions }}
{% for item in conversation %}
<div role="user">{{ item.message }}</div>
<div role="assistant">
<think>{{ item.reasoning }}</think>
{{ item.response }}
</div>
{% endfor %}
<div role="user">
<Instruction>
Now you are required to answer the query based on the context.
Your output must be quoted in <Answer></Answer> tags.
</Instruction>
<Context>
{{ context }}
</Context>
<Query>
{{ query }}
</Query>
</div>
💡 Check out example.py and example.jinja for a comprehensive example with all features!
[!WARNING] You can use any HTML-like tags in your prompt, other than the reserved tags. However, all tags must be properly closed (e.g.,
<instruct> content </instruct>not<instruct> content) to avoid parsing errors.
Roles
Prompt Bottle supports four main roles:
system: System instructions and configuration. Default of raw text.user: User messages and queriesassistant: AI assistant responsestool: Tool execution results
Response Types
Assistant responses can include multiple content tags:
<text>: Regular text content. Default of raw text.<tool_call>: Function/tool invocations<think>: Reasoning and thought processes
Request Types
TODO: Will support multimodal input in the future.
API Reference 📖
render(template: str, **kwargs) -> list[ModelMessage]
Renders a Jinja template with the provided variables and returns structured messages.
Parameters:
template: Jinja template string**kwargs: Template variables
Returns: List of pydantic-ai ModelMessage objects (ModelRequest/ModelResponse)
to_openai_chat(messages: list[ModelMessage], **model_kwargs) -> list[dict]
Converts structured messages to OpenAI chat completion format.
Parameters:
messages: List of ModelMessage objects from render()**model_kwargs: OpenAI model configuration (default model: gpt-4o)
Returns: List of OpenAI-formatted message dictionaries
Contributing 🤝
Contributions are welcome! Please feel free to submit a Pull Request.
License 📄
This project is licensed under the MIT License - see the LICENSE file for details.
Links 🔗
velin: Vue.js based prompt template engine
Release files for prompt_bottle 0.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| prompt_bottle-0.4.1.tar.gz | 6.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| prompt_bottle-0.4.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.5 kB
Release files / prompt_bottle-0.4.1.tar.gz
| Download URL | prompt_bottle-0.4.1.tar.gz |
|---|---|
| Size | 6.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8627dec761febe419b6c40aa50474da98d23300b3a0ddb6fc9dd4c5bbb3966b0
|
|
BLAKE2b-256 checksum How to use checksums |
9536475185703893868e3d0e4d1bff5bf63ba0fa52ab14c1e7e0d8c8fcda941b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
pdm/2.25.9 CPython/3.13.7 Linux/6.11.0-1018-azure
|
Release files / prompt_bottle-0.4.1-py3-none-any.whl
| Download URL | prompt_bottle-0.4.1-py3-none-any.whl |
|---|---|
| Size | 7.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
52fd82f95ac44c3715a4a22f90de0a9ef6b2978a3aeb495f167203d4686c2c99
|
|
BLAKE2b-256 checksum How to use checksums |
976eb0c1acb796da87bc91712f325c1c41d5d95a5d592621960a5aa937c6ccdc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
pdm/2.25.9 CPython/3.13.7 Linux/6.11.0-1018-azure
|