Skip to main content
Concept overview: The Requirements System explains the design and trade-offs.
Prerequisites: The Requirements System, Quick Start complete, pip install mellea. Custom verifiers are Python functions that inspect LLM output and return a ValidationResult. Mellea calls them as part of the IVR loop: when a verifier returns False, Mellea sends the reason back to the model and retries.

The simple_validate shortcut

For checks that only need the most recent output string, use simple_validate:
Use simple_validate when your logic only needs the output text and has no side effects. For anything beyond that — JSON parsing with error details, external API calls, access to conversation history — write a full validation function.

Writing a full validation function

A validation function receives the Context object and returns a ValidationResult. The most common pattern is to inspect the last model output:
Attach it to a Requirement:

Common validation patterns

JSON validity

Pydantic schema conformance

Regex patterns

External API or database check

Validation functions are synchronous. For checks that call external systems, make the call inline:
Note: External calls in validators add latency to every validation attempt. Keep them fast and idempotent — the validator may be called multiple times per instruct() call if the IVR loop retries.

Using ValidationResult.score

Some validators produce a numeric confidence score rather than a binary result. Include it for observability and to support scoring-based sampling strategies:

Composing multiple verifiers

Mix simple_validate and full validation functions freely in a requirements list:
All requirements are evaluated after each generation attempt. Mellea collects every failure and includes all failure reason strings in the repair request, so the model can address multiple issues in a single pass.

Debugging verifier failures

Use return_sampling_results=True to inspect which requirements failed and why:
This pattern is useful during development to confirm your verifier fires at the right time and produces helpful repair guidance.
See also: The Requirements System | Instruct, Validate, Repair