banks

2.4.1 · active · verified Thu Apr 09

Banks (version 2.4.1) is a Python library designed as a prompt programming language for Large Language Models (LLMs). It simplifies the creation, templating, versioning, and management of LLM prompts, offering an intuitive alternative to f-strings for complex prompt engineering. The library maintains an active and frequent release cadence, continuously adding features and improvements.

Warnings

Install

Imports

Quickstart

This example demonstrates how to define a multi-turn chat prompt using Banks' templating syntax and then render it into a list of chat messages suitable for Large Language Model (LLM) APIs.

from banks import Prompt

# Define a prompt template using Banks' templating language
prompt_template = """
{% chat role="system" %}
You are a {{ persona }}.
{% endchat %}

{% chat role="user" %}
Hello {{ name }}!
{% endchat %}
"""

# Create a Prompt object
p = Prompt(prompt_template)

# Render the prompt with context to generate chat messages
chat_messages = p.chat_messages({"persona": "friendly assistant", "name": "Alice"})

# Print the generated chat messages (e.g., for use with an LLM client)
print(chat_messages)

# Expected output:
# [{'role': 'system', 'content': 'You are a friendly assistant.'},
#  {'role': 'user', 'content': 'Hello Alice!'}]

view raw JSON →