Description
# banks [](https://pypi.org/project/banks) [](https://pypi.org/project/banks) [](https://coveralls.io/github/masci/banks?branch=main) [](https://github.com/masci/banks/actions/workflows/release.yml) [](https://github.com/masci/banks/actions/workflows/test.yml) [](https://github.com/masci/banks/actions/workflows/docs.yml) [](https://github.com/pypa/hatch) [](https://github.com/astral-sh/ruff) [](https://mypy-lang.org/) [](https://spdx.org/licenses/) [Banks](https://en.wikipedia.org/wiki/Arrival_(film)) is the linguist professor who will help you generate meaningful LLM prompts using a template language that makes sense. If you're still using `f-strings` for the job, keep reading. Docs are available [here](https://masci.github.io/banks/).  ----- **Table of Contents** - [banks](#banks) - [Installation](#installation) - [Features](#features) - [Cookbook](#cookbook) - [Examples](#examples) - [:point\_right: Render a prompt template as chat messages](#point_right-render-a-prompt-template-as-chat-messages) - [:point\_right: Add images to the prompt for vision models](#point_right-add-images-to-the-prompt-for-vision-models) - [:point\_right: Use a LLM to generate a text while rendering a prompt](#point_right-use-a-llm-to-generate-a-text-while-rendering-a-prompt) - [:point\_right: Function calling directly from the prompt](#point_right-function-calling-directly-from-the-prompt) - [:point\_right: Use prompt caching from Anthropic](#point_right-use-prompt-caching-from-anthropic) - [Reuse templates from registries](#reuse-templates-from-registries) - [Async support](#async-support) - [Contributing](#contributing) - [License](#license) ## Installation ```console pip install banks # install optional deps; litellm, redis pip install "banks[all]" ``` ## Features Prompts are instrumental for the success of any LLM application, and Banks focuses around specific areas of their lifecycle: - :orange_book: **Templating**: Banks provides tools and functions to build prompts text and chat messages from generic blueprints. - :tickets: **Versioning and metadata**: Banks supports attaching metadata to prompts to ease their management, and versioning is first-class citizen. - :file_cabinet: **Management**: Banks provides ways to store prompts on disk along with their metadata. ## Cookbook - :blue_book: [In-prompt chat completion](./cookbook/in_prompt_completion.ipynb) - :blue_book: [Prompt caching with Anthropic](./cookbook/Prompt_Caching_with_Anthropic.ipynb) - :blue_book: [Prompt versioning](./cookbook/Prompt_Versioning.ipynb) ## Examples For a more extensive set of code examples, [see the documentation page](https://masci.github.io/banks/examples/). ### :point_right: Render a prompt template as chat messages You'll find yourself feeding an LLM a list of chat messages instead of plain text more often than not. Banks will help you remove the boilerplate by defining the messages already at the prompt level. ```py from banks import Prompt prompt_template = """ {% chat role="system" %} You are a {{ persona }}. {% endchat %} {% chat role="user" %} Hello, how are you? {% endchat %} """ p = Prompt(prompt_template) print(p.chat_messages({"persona": "helpful assistant"})) # Output: # [ # ChatMessage(role='system', content=[ # ContentBlock(type=<ContentBlockType.text: 'text'>, cache_control=None, text='You are a helpful assistant.', # image_url=None, input_audio=None, input_video=None, input_document=None) # ], tool_call_id=None, name=None), # ChatMessage(role='user', content=[ # ContentBlock(type=<ContentBlockType.text: 'text'>, cache_control=None, text='Hello, how are you?', # image_url=None, input_audio=None, input_video=None, input_document=None) # ], tool_call_id=None, name=None) # ] ``` ### :point_right: Add images to the prompt for vision models If you're working with a multimodal model, you can include images directly in the prompt, and Banks will do the job needed to upload them when rendering the chat messages: ```py import litellm from banks import Prompt prompt_template = """ {% chat role="user" %} Gues
Release History
| Version | Changes | Urgency | Date |
|---|---|---|---|
| 2.4.1 | Imported from PyPI (2.4.1) | Low | 4/21/2026 |
| v2.4.1 | ## What's Changed * CI: explicitly ignore missing stubs for griffe by @masci in https://github.com/masci/banks/pull/72 * fix: add back support for Python 3.9 by @yuqi1129 in https://github.com/masci/banks/pull/71 ## New Contributors * @yuqi1129 made their first contribution in https://github.com/masci/banks/pull/71 **Full Changelog**: https://github.com/masci/banks/compare/v2.4.0...v2.4.1 | Low | 2/17/2026 |
| v2.4.0 | ## What's Changed * Support binary inputs to Image, Audio, Video, and Document types by @bschloss in https://github.com/masci/banks/pull/67 * docs: move AI guidance to AGENTS.md for tool-agnostic access by @masci in https://github.com/masci/banks/pull/69 **Full Changelog**: https://github.com/masci/banks/compare/v2.3.0...v2.4.0 | Low | 2/6/2026 |
| v2.3.0 | ## What's Changed * fix typing and linting with latest Python by @masci in https://github.com/masci/banks/pull/62 * add support for audio URL by @masci in https://github.com/masci/banks/pull/63 * Stop testing on Python 3.9, introduce Python 3.14 by @masci in https://github.com/masci/banks/pull/64 * feat: Support Documents by @bschloss in https://github.com/masci/banks/pull/66 * feat: Support Video by @bschloss in https://github.com/masci/banks/pull/65 ## New Contributors * @bschloss made their | Low | 1/21/2026 |
| v2.2.0 | ## What's Changed * feat: implement XML filter for Pydantic/dictionary/deserializable string by @AstraBert in https://github.com/masci/banks/pull/59 * fix: add support for base64 URLs to the image filter by @masci in https://github.com/masci/banks/pull/60 **Full Changelog**: https://github.com/masci/banks/compare/v2.1.3...v2.2.0 | Low | 7/18/2025 |
| v2.1.3 | ## What's Changed * fix: populate template path when reading the directory index by @masci in https://github.com/masci/banks/pull/57 **Full Changelog**: https://github.com/masci/banks/compare/v2.1.2...v2.1.3 | Low | 6/27/2025 |
| v2.1.2 | ## What's Changed * fix: fix unknown role error message + other small fixes by @anakin87 in https://github.com/masci/banks/pull/52 * chore: update Chat example in README by @anakin87 in https://github.com/masci/banks/pull/53 * fix: detect multiline text blocks interleaved with image blocks by @masci in https://github.com/masci/banks/pull/55 ## New Contributors * @anakin87 made their first contribution in https://github.com/masci/banks/pull/52 **Full Changelog**: https://github.com/masci/banks/ | Low | 4/20/2025 |
| v2.1.1 | ## What's Changed * Update URLs by @fabaff in https://github.com/masci/banks/pull/48 * fix: add platformdirs as dependency by @masci in https://github.com/masci/banks/pull/49 ## New Contributors * @fabaff made their first contribution in https://github.com/masci/banks/pull/48 **Full Changelog**: https://github.com/masci/banks/compare/v2.1.0...v2.1.1 | Low | 3/31/2025 |
| v2.1.0 | ## What's Changed * Support string as input for DirectoryPromptRegistry and FilePromptRegistry and documentation correction by @AstraBert in https://github.com/masci/banks/pull/44 * improve content block regex by @logan-markewich in https://github.com/masci/banks/pull/47 ## New Contributors * @AstraBert made their first contribution in https://github.com/masci/banks/pull/44 **Full Changelog**: https://github.com/masci/banks/compare/v2.0.0...v2.1.0 | Low | 3/29/2025 |
| v2.0.0 | ## What's Changed * feat: add `variables` property to the Prompt class by @masci in https://github.com/masci/banks/pull/39 * fix: make image filter work outside `{% chat %}` blocks by @masci in https://github.com/masci/banks/pull/38 * [breaking] fix deps again by @logan-markewich in https://github.com/masci/banks/pull/40 * feat: add audio block to chat messages by @masci in https://github.com/masci/banks/pull/41 * feat: add audio filter by @masci in https://github.com/masci/banks/pull/42 | Low | 3/22/2025 |
| v1.8.0 | ## What's Changed * feat: re-introduce support for Python 3.9 by @masci in https://github.com/masci/banks/pull/37 * feat: Make litellm and redis optional dependencies, adding `minimal` extra install option by @logan-markewich in https://github.com/masci/banks/pull/33 ## New Contributors * @logan-markewich made their first contribution in https://github.com/masci/banks/pull/33 **Full Changelog**: https://github.com/masci/banks/compare/v1.7.1...v1.8.0 | Low | 3/14/2025 |
| v1.7.1 | ## What's Changed * fix: fix interleaved blocks in chat messages by @masci in https://github.com/masci/banks/pull/32 **Full Changelog**: https://github.com/masci/banks/compare/v1.7.0...v1.7.1 | Low | 3/1/2025 |
| v1.7.0 | ## What's Changed * Added assistant support to banks for few shot learning by @ArmykOliva in https://github.com/masci/banks/pull/31 ## New Contributors * @ArmykOliva made their first contribution in https://github.com/masci/banks/pull/31 **Full Changelog**: https://github.com/masci/banks/compare/v1.6.1...v1.7.0 | Low | 2/3/2025 |
| v1.6.1 | ## What's Changed * fix: support xml tags inside chat messages by @masci in https://github.com/masci/banks/pull/30 **Full Changelog**: https://github.com/masci/banks/compare/v1.6.0...v1.6.1 | Low | 12/31/2024 |
| v1.6.0 | ## What's Changed * chore: remove deprecated 'generate' and 'run_prompt' by @masci in https://github.com/masci/banks/pull/28 * fix: fix function calling with the latest litellm version by @masci in https://github.com/masci/banks/pull/29 **Full Changelog**: https://github.com/masci/banks/compare/v1.5.0...v1.6.0 | Low | 12/1/2024 |
| v1.5.0 | ## What's Changed * feat: Add Redis prompt registry by @masci in https://github.com/masci/banks/pull/21 * feat: Add `image` tag filter to support images within a prompt for vision models by @masci in https://github.com/masci/banks/pull/22 * feat: remove deprecated extension `HFInferenceEndpointsExtension` by @masci in https://github.com/masci/banks/pull/23 * fix: adjust to latest litellm changes by @masci in https://github.com/masci/banks/pull/26 * fix colab link in recipe by @masci in http | Low | 11/25/2024 |
| v1.4.0 | ## What's Changed * feat: Add function calling from `{% completion %}` by @masci in https://github.com/masci/banks/pull/20 **Full Changelog**: https://github.com/masci/banks/compare/v1.3.0...v1.4.0 | Low | 10/17/2024 |
| v1.3.0 | ## What's Changed * feat: add completion extension by @masci in https://github.com/masci/banks/pull/19 **Full Changelog**: https://github.com/masci/banks/compare/v1.2.1...v1.3.0 | Low | 10/12/2024 |
| v1.2.1 | ## What's Changed * fix: return a single chat message instead of an empty list when template has no `{% chat %}` tags by @masci in https://github.com/masci/banks/pull/18 **Full Changelog**: https://github.com/masci/banks/compare/v1.2.0...v1.2.1 | Low | 10/7/2024 |
| v1.2.0 | ## What's Changed * fix: re-add Python 3.10 support by @masci in https://github.com/masci/banks/pull/17 **Full Changelog**: https://github.com/masci/banks/compare/v1.1.0...v1.2.0 | Low | 10/6/2024 |
| v1.1.0 | ## What's Changed * feat: add `cache_control` filter to support prompt caching in Anthropic by @masci in https://github.com/masci/banks/pull/16 **Full Changelog**: https://github.com/masci/banks/compare/v1.0.0...v1.1.0 | Low | 10/6/2024 |
| v1.0.0 | ## What's Changed * feat: add meta and version to the Prompt class by @masci in https://github.com/masci/banks/pull/12 * feat: add `name` field to Prompt by @masci in https://github.com/masci/banks/pull/13 * refact: new registry api by @masci in https://github.com/masci/banks/pull/14 * feat: Add support for chat messages via custom tag `{% chat %}` by @masci in https://github.com/masci/banks/pull/15 **Full Changelog**: https://github.com/masci/banks/compare/v0.6.0...v1.0.0 | Low | 10/3/2024 |
| v0.6.0 | ## What's Changed * feat & bugfix: Added metadata features and fixed naming bug by @mayankjobanputra in https://github.com/masci/banks/pull/11 **Full Changelog**: https://github.com/masci/banks/compare/v0.5.0...v0.6.0 | Low | 9/7/2024 |
| v0.5.0 | ## What's Changed * feat: cache prompt rendering by @masci in https://github.com/masci/banks/pull/4 * Added CITATION.cff by @mayankjobanputra in https://github.com/masci/banks/pull/5 * feat: Introduce prompt registry, support versioning in `Prompt.from_template` by @masci in https://github.com/masci/banks/pull/6 * fix python supported versions and added a check for : in template name by @mayankjobanputra in https://github.com/masci/banks/pull/7 * Create a global config object by @masci in | Low | 8/15/2024 |
| v0.4.1 | ## What's Changed * fix: Fix a regression in the `generate` extension. by @masci in https://github.com/masci/banks/pull/3 **Full Changelog**: https://github.com/masci/banks/compare/v0.4.0...v0.4.1 | Low | 5/3/2024 |
| v0.4.0 | ## What's Changed * feat: Add canary word support by @masci in https://github.com/masci/banks/pull/2 ## New Contributors * @masci made their first contribution in https://github.com/masci/banks/pull/2 **Full Changelog**: https://github.com/masci/banks/compare/v0.3.1...v0.4.0 | Low | 5/2/2024 |
| v0.3.1 | - Remove debug `print`s | Low | 4/27/2024 |
| v0.3.0 | - Add `asyncio` support | Low | 4/27/2024 |
| v0.2.0 | **Full Changelog**: https://github.com/masci/banks/compare/v0.1.1...v0.2.0 | Low | 4/12/2024 |
