Your docstring is the prompt, your type hint is the contract
Mellea treats LLM calls as typed Python functions, turning docstrings into prompts and Pydantic models into enforceable output contracts.

What it does
Mellea provides a @generative decorator that turns ordinary Python functions into structured LLM calls. You write a docstring and a return type—usually a Pydantic model—and the library handles the prompting, schema enforcement, and automatic retries when outputs drift. It supports multiple backends including Ollama, OpenAI, HuggingFace, and Bedrock, and can expose these functions as MCP tools.
The interesting bit
The library flips the usual script: instead of hand-crafting prompts and then parsing JSON, your type annotations become the generation contract enforced at runtime. It also bakes in sampling strategies like rejection sampling and majority voting, so you can trade latency for reliability without rewriting the call site.
Key highlights
@generativedecorator maps docstrings to prompts and type hints to Pydantic schemas- Natural-language requirements attach to calls, with automatic validation and retry loops
- Built-in sampling strategies (rejection sampling, majority voting) selectable via parameter
- Multiple backend support: Ollama, OpenAI, HuggingFace, WatsonX, LiteLLM, Bedrock
- MCP-compatible: any generative program can be exposed as an MCP tool, and legacy code can adopt it via
mify
Verdict
Developers who are tired of prompt archaeology and manual output parsing should look here; if you are happy with ad-hoc string completion and don’t need schema guarantees, it is probably overkill.
Frequently asked
- What is generative-computing/mellea?
- Mellea treats LLM calls as typed Python functions, turning docstrings into prompts and Pydantic models into enforceable output contracts.
- Is mellea open source?
- Yes — generative-computing/mellea is open source, released under the Apache-2.0 license.
- What language is mellea written in?
- generative-computing/mellea is primarily written in Python.
- How popular is mellea?
- generative-computing/mellea has 1.8k stars on GitHub and is currently cooling off.
- Where can I find mellea?
- generative-computing/mellea is on GitHub at https://github.com/generative-computing/mellea.