Precise
Write generative functions using code. The @generative decorator handles the communication with the LLM.
Make outputs precise, predictable, and repeatable with Mellea’s library of generative functions.
Mellea is a Python library for working with LLMs using generative functions.
In traditional programming, functions turn inputs into deterministic outputs. Mellea builds on this by allowing functions to call LLMs to create an output, but with customizable requirements that maintain the rigor of professional software development. If an LLM returns something that doesn’t meet a requirement, Mellea will automatically try it again. This means you can build applications that make use of the power of LLMs while keeping all the benefits of reliable, testable Python code.
Write generative functions using code. The @generative decorator handles the communication with the LLM.
Set the requirements that you want Mellea to validate. Automatic retries mean unwanted outputs never reach your users.
Expose any Mellea program as an MCP tool. The calling agent gets the same validated, predictable output as other Mellea users.
Built-in Granite Guardian integration detects harmful outputs, hallucinations, and jailbreak attempts before they reach your users — no external service required.
Granite is a family of models built with enterprises in mind. It has open-weights for transparency, comes in sizes from 350M-32B parameters, and offers an extensive adapter library. This means it can take on specific tasks with the performance of a much larger model while keeping its nimble speed and low costs.
Mellea is designed to be Granite’s SDK. Together, they offer a flexible way to build AI applications that are transparent from the ground up and only do what you want them to.
Mellea v0.8.0 adds audio as an input modality, lets you retrieve the files your sandboxed code produced, cuts m CLI startup from 3.2s to 0.1s, and rebuilds streaming as a plain async iterator. There are breaking changes to review if you use streaming or telemetry.
TypeSafe's Jev answers typed questions with probabilities instead of generating text. Mellea has been going at validation from the same direction, starting with the cheapest check that will do the job.
Vision models return prose. This post shows how to get a typed Python object back instead, using Mellea's format= parameter and ImageBlock.