About Mellea
Mellea is an open source Python library, released under Apache 2.0, for getting structured, validated and testable output from large language models. It treats each LLM call as something a developer can specify, test and reason about, rather than a prompt that fails silently.
The core idea is that Python code, not prose, defines the behavior. A generative decorator turns a typed function signature into an LLM specification, so the docstring acts as the prompt and the type hints act as the schema. Developers declare requirements such as tone, length, content or custom logic, and Mellea checks every output and retries automatically when it falls short. Grammar constrained decoding is supported for Ollama, vLLM and HuggingFace, enforcing valid output at the token level instead of retrying. Higher confidence can be had by switching from a single attempt to majority voting or best of n with one parameter. Any Mellea program can be exposed as an MCP tool, and Granite Guardian integration checks for harmful output, hallucinations and jailbreak attempts.
It works with OpenAI, Ollama, vLLM, HuggingFace, Watsonx, LiteLLM and Bedrock, and is aimed at Python developers who build pipelines, workflows and agents on LLM calls. Version 0.6 added streaming with per chunk validation and an OpenTelemetry bridge.
Install it with uv pip install mellea. The library is free, and the site lists no paid plans.