mellea is a library for writing generative programs
Project description
Mellea — build predictable AI without guesswork
Inside every AI-powered pipeline, the unreliable part is the same: the LLM call itself. Silent failures, untestable outputs, no guarantees. 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.
Install
uv pip install mellea
See installation docs for additional options, such as installing all extras via uv pip install 'mellea[all]'.
For source installation directly from this repo, see CONTRIBUTING.md.
Example
The @generative decorator turns a typed Python function into a structured LLM call.
Docstrings become prompts, type hints become schemas — no templates, no parsers:
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
What Mellea Does
- Structured output —
@generativeturns typed functions into LLM calls; Pydantic schemas are enforced at generation time - Requirements & repair — attach natural-language requirements to any call; Mellea validates and retries automatically
- Sampling strategies — run a generation multiple times and pick the best result; swap between rejection sampling, majority voting, and more with one parameter change
- Multiple backends — Ollama, OpenAI, HuggingFace, WatsonX, LiteLLM, Bedrock
- Legacy integration — easily drop Mellea into existing codebases with
mify - MCP compatible — expose any generative program as an MCP tool
Learn More
| Resource | Description |
|---|---|
| docs.mellea.ai | Full docs — vision, tutorials, API reference, how-to guides |
| Colab notebooks | Interactive examples you can run immediately |
| Code examples | Runnable examples: RAG, agents, Instruct-Validate-Repair (IVR), MObjects, and more |
Contributing
We welcome contributions of all kinds — bug fixes, new backends, standard library components, examples, and docs.
- Contributing Guide — development setup, workflow, and coding standards
- Building Extensions — create reusable components in your own repo
- mellea-contribs — community library for shared components
Questions? See GitHub Discussions.
IBM ❤️ Open Source AI
Mellea was started by IBM Research in Cambridge, MA.
Licensed under the Apache-2.0 License. Copyright © 2026 Mellea.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mellea-0.4.2.tar.gz.
File metadata
- Download URL: mellea-0.4.2.tar.gz
- Upload date:
- Size: 4.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
054fb4d4082674fa23482f705639d2ee19ddc4d241ffc6834944066b0a9e139d
|
|
| MD5 |
1bd0f96be6f7bdd855e01f648b85feae
|
|
| BLAKE2b-256 |
2f41210d0842847c2977ae26834f3f93ea824a3faeaa2b516315131dfaec672a
|
Provenance
The following attestation bundles were made for mellea-0.4.2.tar.gz:
Publisher:
pypi.yml on generative-computing/mellea
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mellea-0.4.2.tar.gz -
Subject digest:
054fb4d4082674fa23482f705639d2ee19ddc4d241ffc6834944066b0a9e139d - Sigstore transparency entry: 1258036545
- Sigstore integration time:
-
Permalink:
generative-computing/mellea@faf02f8a827df4be7d0a539eeb5349f2f47bc247 -
Branch / Tag:
refs/tags/v0.4.2 - Owner: https://github.com/generative-computing
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@faf02f8a827df4be7d0a539eeb5349f2f47bc247 -
Trigger Event:
release
-
Statement type:
File details
Details for the file mellea-0.4.2-py3-none-any.whl.
File metadata
- Download URL: mellea-0.4.2-py3-none-any.whl
- Upload date:
- Size: 4.4 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf31ecb897b49767069f5e2fbd09834148d99a322fbc957003a262269eb7de82
|
|
| MD5 |
13bdf54a2182f3a8c866d44d6bbdb9f0
|
|
| BLAKE2b-256 |
a99ca163fb82851bf81a1f0ede0851786bfa9f1bf6bdb8cad8e79d87ac15973a
|
Provenance
The following attestation bundles were made for mellea-0.4.2-py3-none-any.whl:
Publisher:
pypi.yml on generative-computing/mellea
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mellea-0.4.2-py3-none-any.whl -
Subject digest:
cf31ecb897b49767069f5e2fbd09834148d99a322fbc957003a262269eb7de82 - Sigstore transparency entry: 1258036838
- Sigstore integration time:
-
Permalink:
generative-computing/mellea@faf02f8a827df4be7d0a539eeb5349f2f47bc247 -
Branch / Tag:
refs/tags/v0.4.2 - Owner: https://github.com/generative-computing
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@faf02f8a827df4be7d0a539eeb5349f2f47bc247 -
Trigger Event:
release
-
Statement type: