Skip to main content

Why does start_session() fail with a connection error?

Mellea’s default backend is Ollama. If Ollama is not running, any call that reaches the backend raises a connection error:
Start Ollama and try again:
Verify the server is reachable before running your script:
If Ollama is running on a non-default host or port, pass the URL explicitly:

How do I use a model other than granite4.1:3b?

Pass the model_id parameter to start_session():
Pull the model with Ollama before using it:
You can also pass a backend instance directly to MelleaSession for full control over backend options:

Can I use Mellea without Ollama?

Yes. Ollama is the default backend but not the only one. Mellea ships with backends for OpenAI-compatible APIs, HuggingFace local inference, IBM WatsonX, and LiteLLM (which itself proxies dozens of providers). Install the backend you need:
Then pass the backend to start_session() or MelleaSession:
See Common Errors for help installing backend-specific dependencies.

Why does my @generative function return the wrong type?

The @generative decorator uses the function’s docstring as the prompt. If the docstring is vague, the model may return output that cannot be parsed into the declared return type. Compare these two definitions:
For stricter guarantees, add requirements:
If the function raises ComponentParseError, add an example to the docstring — the model needs a concrete illustration of the expected format.

What is the difference between instruct() and @generative?

Both call the LLM, but they differ in when you write the prompt and how you pass variables. instruct() takes a prompt string with {{variable}} placeholders at call time. It is best for one-off instructions where the prompt text varies:
@generative defines the prompt once in the function’s docstring. It is best when you want a reusable, typed, unit-testable function:
@generative functions also participate in Mellea’s lazy evaluation graph, which means you can feed a thunk from one generative call into another before either has been evaluated.

Why do requirements keep failing?

When the model keeps retrying but the output looks correct, one of the following is usually the cause:
  • The requirement is too strict. A requirement like “Must be exactly 17 syllables” is difficult for a model to satisfy reliably. Relax the constraint or provide the model with more context.
  • The default budget is too low. instruct() defaults to loop_budget=2. Increase it:
  • The validation function is wrong. If you are using a custom verifier, check it returns True for valid output. Use return_sampling_results=True to inspect each attempt:

How do I see what the model is actually receiving?

Use GenerateLog to capture the rendered prompt. Enable application tracing or backend tracing and check the response and gen_ai.usage.input_tokens attributes on the spans. For a quick local inspection without a trace backend, enable console tracing:
Each backend span prints the operation name, model ID, and token counts. Alternatively, inspect the GenerateLog objects returned with sampling results:
For the full telemetry setup, see Tracing.

Does Mellea support async?

Yes. Every synchronous method has an async counterpart: @generative functions work in async context when you await them:
Note: If you are inside a Jupyter notebook, the event loop is already running. Use await directly or install nest_asyncio to allow nested loops.

How do I contribute?

Read the contributing guide first:
The short version:
  1. Fork the repository and clone it.
  2. Install dependencies: uv sync --all-extras --all-groups
  3. Install pre-commit hooks: pre-commit install
  4. Create a branch: git checkout -b feat/your-feature
  5. Run tests: uv run pytest -m "not qualitative"
  6. Open a pull request.
All commits use Angular format (feat:, fix:, docs:, refactor:). Pre-commit runs ruff, mypy, and codespell automatically.

Where can I get help?

  • GitHub Issues: Report bugs and request features at the project’s GitHub Issues page.
  • GitHub Discussions: Ask questions and share ideas in the Discussions tab.
  • Examples: The docs/examples/ directory contains runnable examples covering every major feature.
  • Common Errors: See Common Errors for a reference table of known error messages and fixes.

See also

  • Common Errors — a reference table of error messages, diagnostic steps, and fixes.
  • Quick Start — install Mellea and run your first generative function.