Mellea is a Python library for writing generative programs, offering structured, testable AI workflows with typed outputs and automatic retries. It supports multiple backends and provides a decorator to convert typed functions into LLM calls.
Collecting history — the radar snapshots this repo daily. The trend line appears after 3 days of data (1 so far).
What it is
Mellea is a Python library for writing generative programs — replacing brittle prompts and flaky agents with structured, testable AI workflows built around type-annotated outputs, verifiable requirements, and automatic retries.
How it works
- The library uses a @generative decorator to turn typed Python functions into LLM calls. Docstrings become prompts, and type hints become schemas.
- It provides features such as structured output, requirements & repair with automatic validation and retries, and multiple sampling strategies (e.g., run a generation multiple times and pick the best result).
- Supports multiple backends: Ollama, OpenAI, HuggingFace, WatsonX, LiteLLM, Bedrock.
- Offers legacy integration via mify and MCP compatibility to expose generative programs as MCP tools.
Getting started
Install:
uv pip install mellea
See installation docs for additional options, such as installing all extras via uv pip install 'mellea[all]'.
Example usage excerpt from README:
from pydantic import BaseModel
from mellea import generative, start_session
class UserProfile(BaseModel):
name: str
age: int
@generative
def extract_user(text: str) -> UserProfile:
"""Extract the user's name and age from the text."""
m = start_session()
user = extract_user(m, text="User log 42: Alice is 31 years old.")
print(user.name) # Alice
print(user.age) # 31 — always an int, guaranteed by the schema
Recent releases
- v0.7.0 (2026-07-13): New features include implementing a release-branch workflow.
- v0.6.0 (2026-05-19): Added typing to mellea tools.
- v0.5.0 (2026-05-05): Latency histograms for LLM request duration and TTFB.
- v0.4.2 (2026-04-08): Added tests for mellea optional dependencies.
- v0.4.1 (2026-03-23): Move ruff hooks locally; update CI/CD autofixes and related changes.
Traction
Repository has 1783 stars and 171 open issues.
Behind the repo
IBM Research contributed to the project; project page notes LM-backed generative workflow tooling.
Caveats
License: Apache-2.0. Created: 2025-07-31. Last push: 2026-08-04.






