A lightweight Python framework for building modular, schema-driven AI agent pipelines on top of Instructor and Pydantic.
generative-computing/mellea
Python library for writing generative programs that turn typed LLM calls into structured, testable, and self-validating AI workflows.
- Stars
- 1,851
- Forks
- 177
- Open issues
- 161
- Last commit
- 11 hours ago
What is it?
Mellea is a Python library aimed at making LLM-powered pipelines more predictable. Instead of hand-written prompt templates and output parsers, a function annotated with a Pydantic return type and decorated with @generative becomes a structured LLM call, with the docstring serving as the prompt.
Beyond structured output, Mellea lets you attach natural-language requirements to a call and automatically validates the result, retrying when a requirement is not met. Sampling strategies such as rejection sampling and majority voting can be switched with a single parameter. The library supports multiple model backends, including Ollama, OpenAI, HuggingFace, WatsonX, LiteLLM and Bedrock.
Existing codebases can adopt Mellea incrementally through the mify helper, and any generative program can be exposed as an MCP tool. The project is installable from PyPI and is maintained by IBM Research.
Key features
- 01Turns typed Python functions into LLM calls with Pydantic-enforced output schemas.
- 02Attaches natural-language requirements to calls and retries until they pass.
- 03Switches between sampling strategies such as rejection sampling and majority voting.
- 04Supports Ollama, OpenAI, HuggingFace, WatsonX, LiteLLM and Bedrock backends.
- 05Lets legacy code adopt it via the mify helper.
- 06Exposes generative programs as MCP tools.
Use cases
- Extracting structured records such as profiles or fields from unstructured text.
- Adding output validation and automatic retries to LLM steps in a production pipeline.
- Wrapping LLM functions as MCP tools for agent frameworks.
- Comparing sampling strategies to improve answer quality without changing application code.
Quick start
- 1
Install the library with uv
uv pip install mellea - 2
Save the README example and run it (needs a running LLM backend such as Ollama)
Things to know
- Each LLM call needs a configured backend such as Ollama, OpenAI, or WatsonX, so you must provide model access yourself.
In collections
Topics
FAQ
- What is mellea?
- Python library for writing generative programs that turn typed LLM calls into structured, testable, and self-validating AI workflows. Mellea is a Python library aimed at making LLM-powered pipelines more predictable. Instead of hand-written prompt templates and output parsers, a function annotated with a Pydantic return type and decorated with @generative becomes a structured LLM call, with the docstring serving as the prompt.
- Is mellea free to use? What license does it have?
- mellea is open source under the Apache-2.0 license. Check the license terms before using it in commercial products.
- Is mellea still maintained?
- Actively maintained. The last commit to mellea was on Nov 6, 2026.
- What can I use mellea for?
- Extracting structured records such as profiles or fields from unstructured text. Adding output validation and automatic retries to LLM steps in a production pipeline. Wrapping LLM functions as MCP tools for agent frameworks. Comparing sampling strategies to improve answer quality without changing application code.
- How do I install mellea?
- Install the library with uv: uv pip install mellea Save the README example and run it (needs a running LLM backend such as Ollama)
- Where can I get mellea?
- The source code and installation instructions are on GitHub: https://github.com/generative-computing/mellea
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A Dart and Flutter port of LangChain for building LLM-powered apps with pluggable model providers, RAG, and agents.
A Python framework that adds input and output guards to LLM applications and generates validated structured data from LLM outputs.
A lightweight Python decorator library that turns docstrings into LLM prompts, with Pydantic outputs, tool calling, streaming and memory, built on LiteLLM.
A Python library for working with LLMs through objects and types, letting developers prompt models and get structured outputs.
A Python framework for building MCP servers, clients, and interactive apps that connect LLMs to tools and data.