Skip to main content

mellea is a library for writing generative programs

Project description

Mellea logo

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.

Website Docs PyPI version PyPI - Python Version uv Ruff pre-commit GitHub License Contributor Covenant

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

start_session() is the convenience entry point: it returns a MelleaSession with sensible defaults you can override as needed.

What Mellea Does

  • Structured output@generative turns 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.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mellea-0.5.0.tar.gz (4.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mellea-0.5.0-py3-none-any.whl (4.6 MB view details)

Uploaded Python 3

File details

Details for the file mellea-0.5.0.tar.gz.

File metadata

  • Download URL: mellea-0.5.0.tar.gz
  • Upload date:
  • Size: 4.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for mellea-0.5.0.tar.gz
Algorithm Hash digest
SHA256 2f2a37ac286c5f3d950857b5ec214eb37dcd8ef624883aeb09acb0a10cb1a573
MD5 ab66fbbd18064a133bbe7faca30ee8d3
BLAKE2b-256 5f0cbba8f3a32c52ba28f10862e258d7aa625c030eb462f11da69cefb3f0be7f

See more details on using hashes here.

Provenance

The following attestation bundles were made for mellea-0.5.0.tar.gz:

Publisher: pypi.yml on generative-computing/mellea

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mellea-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: mellea-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 4.6 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for mellea-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f450d9fe9f7207a4def17d1861fb3516366b3c5abd5e7f63b00ffd1f4681b0a0
MD5 cfb4f147981260a4318e17942ae7046f
BLAKE2b-256 3bb004b25e4193e7c67e97090b59c053c9d4905321799b02c3783d3e04ec5acf

See more details on using hashes here.

Provenance

The following attestation bundles were made for mellea-0.5.0-py3-none-any.whl:

Publisher: pypi.yml on generative-computing/mellea

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page